Player info can't be accessed by anyone when in room?

Options
Hello there

The last few hours I've been dealing with a really strange problem.

So what I want to do is have a string list (called PlayerNames here) hold all the player names in a room (sorted in the way i describe in the code) and then load the game (in the awake function of the script I have the DontDestroyOnLoad function happening).
However (although it worked fine other times I did it) when I try to access PhotoNetwork.masterClient.name from a client that is not the master I get a null string. Also when I try to get PhotonNetwork.otherplayers info (from the same client) I also get nothing. When I run it as a masterclient I can only get the PhotoNetwork.masterClient.name info but still nothing else. What am I doing wrong? (I debugged the connection state and it is "Joined" for all players so I guess it has nothing to do with connection problems)

Here is the code:
public void GoClicked(){
		Debug.Log ("Starting Game!! ");

		GetComponent<PhotonView>().RPC("LoadTheGame", PhotonTargets.AllBuffered, null);

	}

	[RPC]
	void LoadTheGame(){

		string MastersNameAndID = PhotonNetwork.masterClient.name;

		Debug.Log ("MastersNameAndID: " + MastersNameAndID); // here i get "MAsterNameAndID: " so there MasterNameAndID is null (?)
		
		//we need to have the list ordered for every player , so we have the room-master first and then all the others in alphabetical order...
		
		List <string> unsortedOtherPlayersAndMe = new List<string>();
		
		if(PhotonNetwork.playerName == MastersNameAndID){
			PlayerNames.Add (MastersNameAndID);
		}
		else{
			PlayerNames.Add (MastersNameAndID);
			unsortedOtherPlayersAndMe.Add(PhotonNetwork.playerName);
		}
		
		foreach (PhotonPlayer pl in PhotonNetwork.otherPlayers){
			
			string txt = pl.name;   
			
			
			if(txt != MastersNameAndID && txt != ""){
				Debug.Log("Unsorted in txt: "+ txt);
				unsortedOtherPlayersAndMe.Add (txt);
			}
		}
		
		unsortedOtherPlayersAndMe.Sort ();
		
		foreach (string otherP in unsortedOtherPlayersAndMe) {
			Debug.Log("Sorted in otherP: "+ otherP);
			if(otherP != ""){
				PlayerNames.Add(otherP);		
			}
			
		}
		


		inGame = true;
		PhotonNetwork.LoadLevel ("_project");
	}

Please heeelp

Comments

  • vadim
    Options
    Hi,
    Use PhotonNetwork.playerList property to get list of players in room with names.