Cant see players which are already joined.

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on Realtime.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Cant see players which are already joined.

Freel4tte
2011-10-23 18:50:34

I am making a multi player game and now I'm testing it with the Angry Bots Photon demo stripped down to the player model. I already made a login screen, a lobby and a level. When I host a game I join the level and run around and shoot into oblivion and I can see other players who join later then me. But every player who joins next cant see the players already connected before him.

Unity gives the error about Photon id's that are 1000 and over and that such PhotonVIew dont even exist. Is this the cause of the problem or is it something else. And how do I make this work?

Help is really appreciated and thanks in advance!

Comments

Tobias
2011-10-24 08:48:05

Hm, as much as I'd like to dive into debugging this, I can't. Once you modified the projects so heavily, we can't really support everyone.

Most likely you modified some prefab or gameobject which had a script or PhotonView somewhere. You should probably take a look at the Viking Demo or at the Worker Demo. Both have just the essentials in and comparing those with your project might help you identify the broken spot.

Freel4tte
2011-10-24 11:35:39

Thanks for your reply! But generally speaking, what is wrong with wich script when players can't see each other?

dreamora
2011-10-24 14:36:04

you don't buffer the previous instantiations for example so newly connected players are not informed about players already in the game. Thats the most common error basically that leads to this.

Tobias
2011-10-24 15:47:04

Maybe you use GameObject.Instantiate() instead PhotonNetwork.Instantiate()? Then the views are not created on all clients.

Freel4tte
2011-10-24 18:11:06

@dreamora wrote:

you don't buffer the previous instantiations for example so newly connected players are not informed about players already in the game. Thats the most common error basically that leads to this.

Sorry to be a pain in the ass, but where can I find these bufferings. I tried to look for myself but its kind of hard for me to understand it all. It's really important for me to get this fixed so that's why i'm asking so much. :? Thanks for your reply tough!

dreamora
2011-10-24 18:13:23

PhotonNetwork.Instantiate buffers it automatically, same goes for RPCs you send with xxxBuffered as PhotonTarget anything else is not buffered and new players won't know about it at all unless you resent the RPCs etc to them.

Tobias
2011-10-25 08:36:19

Again: Please check your code if you accidentally used GameObject.Instantiate() instead PhotonNetwork.Instantiate()? Then the views are not created on all clients and you don't see others. Buffering of instantiations is done for you. I just wanted to explain the background.

Freel4tte
2011-10-25 11:09:42

@Tobias wrote:

Again: Please check your code if you accidentally used GameObject.Instantiate() instead PhotonNetwork.Instantiate()? Then the views are not created on all clients and you don't see others. Buffering of instantiations is done for you. I just wanted to explain the background.

I checked it and its PhotonNetwork.Instantiate GameObject GO =PhotonNetwork.Instantiate(playerPrefab, transform.position, Quaternion.identity, 0); Sorry for not answering your reply.

Tobias
2011-10-26 15:16:34

Hmm. Then I don't really see how this should happen. Could you provide a minimized package which shows the issue or attach the important code?

Freel4tte
2011-10-28 07:42:56

I don't understand the minimized package part, but I can add the Gamemanager code (I think it's the important code).

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class GameManager : Photon.MonoBehaviour {
	
	public GUISkin skin;
	public Transform playerPrefab;    
	
	public static Transform localPlayer;
    public static List<Transform> players = new List<Transform>();
	
	public static Transform GetClosestPlayer(Vector3 fromPos){

		Transform close = null;
        float dist = -1;
        foreach (Transform tra in players)
        {
            if (tra == null)
            {
                continue;
            }
            float thisD = Vector3.Distance(tra.position, fromPos);
            if (dist == -1 || thisD < dist)
            {
                dist = thisD;
                close = tra;
            }
        }
		return close;
	}


    public static void AddPlayer(Transform tra)
    {		
        players.Add(tra);		
    }
    public static void RemovePlayer(Transform tra)
    {
        players.Remove(tra);
    }

    void Awake ()
	{
		//PhotonNetwork.sendRateOnSerialize = 10;
		//PhotonNetwork.logLevel = NetworkLogLevel.Full;
		
        //Connect to the main photon server. This is the only IP and port we ever need to set(!)
		if (!PhotonNetwork.connected || PhotonNetwork.room == null) {
			PhotonNetwork.Connect("localhost", 5055, "AngryBots");
			PhotonNetwork.JoinRoom("JoinARoom");
		}

        PhotonNetwork.isMessageQueueRunning = true;
        //Spawn our local player
		
        GameObject GO =PhotonNetwork.Instantiate(playerPrefab, transform.position, Quaternion.identity, 0);
    	localPlayer = GO.transform;
		
	}
    
    void OnGUI ()
	{
		GUI.skin = skin;
		GameGUI ();
		if (GUILayout.Button("Retry", GUILayout.Width(75)))
            PhotonNetwork.JoinRoom("JoinARoom");
	}
	
	bool showDebug = false;
	
	void Update ()
	{
		
		if (Input.GetKeyDown (KeyCode.Q))
			showDebug = !showDebug;
	
		if (Input.GetKeyDown (KeyCode.Escape)) {
			Application.Quit();
		}	
		
	}

    /// <summary>
    /// Check if the game is allowed to click here (for starting FIRE etc.)
    /// </summary>
    /// <returns></returns>
    public static bool GameCanClickHere()
    {
     
        List<Rect> rects = new List<Rect>();
        rects.Add( new Rect(0,0,110,55));//Topleft Button
        rects.Add(new Rect(0, Screen.height-35, 275, 35));//Chat

        Vector2 pos = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
        foreach (Rect re in rects)
        {
            if (re.Contains(pos))
                return false;
        }
        return true;

    }

    void GameGUI(){
		GUILayout.Space(32);
        if (GUILayout.Button("Leave"))
        {
            PhotonNetwork.LeaveRoom();
            Application.LoadLevel(Application.loadedLevel+1);
        }
		
		
		
		if(showDebug){
			GUILayout.Label("isMasterClient: "+PhotonNetwork.isMasterClient);
			GUILayout.Label("Players: "+PhotonNetwork.playerList.Count);
			GUILayout.Label ("Ping: " + PhotonNetwork.GetPing());			
		}
		
	}

}

Hope this helps!

Freel4tte
2011-10-28 10:51:48

I have found the thing that made this happen. When I join a room, the Awake part in the GameManager scripts gets activated and Instantiates a playerprefab. But it Instantiates while the login scene is still loaded. So when the game scene is loaded the already Instantiated player is already spawned in the script, but nowhere to be seen in the scene.

My recent solution was to use a GUI.Button to instantiate the playerprefab. I waited untill both players where in the game scene, then clicked the button and both where instantiated in both the players scene's.

Thanks for all your help!

DKReigns
2019-05-06 05:39:38

I have a similar problem. I managed to solved it by creating a GameManager handler and monitors each time a player enters a room. When someone does, it will "refresh" the instance of all players inside. This is similar to @Freel4tte's solution. You can use

public override void OnPlayerEnteredRoom(Photon.Realtime.Player newPlayer)

God bless and happy coding! :smile:

DKReigns
2019-05-06 05:41:41

I use Photon PUN 2 btw.
I know this thread is very old but maybe some newer viewers who are also having the sample problem could stumble upon this thread, so I'll just leave my answer here.

:smile:

M4rCOS
2020-02-08 12:45:20

Hello! I had the same problem and I found out that I was loading my Play scene with SceneManager.LoadLevel instead of PhotonNetwork.LoadLevel.

I know it's a dumb thing but it worked in my case.
Perhaps someone else will be in the same situation so remember to check for this.

Happy coding! :)

Llaarryy
2021-03-11 17:49:59

Hey @M4rCOS

I guess you'll never see this but just in case I wanted to tell you that you just made my day. I was soo frustrated.
Thank you so much, you're awesome!

ButterGuy
2021-05-18 04:04:27

@Freel4tte could you help explain how you fixed it as in showing the code maybe?

ButterGuy
2021-05-18 04:16:05

@DKReigns Was there anything to input within brackets after putting that or did it work alone?

AssassinSquidGames
2022-01-20 03:51:08

@M4rCOS THANK YOU!!!! I was so lost. I'm glad it only took me an hour and a half to find this

Back to top