[PUN] Duplicates data in master client and client custom properties
I guys. I face a strange behaviour with PUN. This is my use case : I have two players, ted and kosted.
Let's suppose that kosted creates the room. In the room he sets his custom property and get "type = Rouge". When the 2nd player joins this room get get the "type=Bleu".
if (PhotonNetwork.isMasterClient) //master client is the first to connect
{
Debug.Log("je suis dans le master");
ExitGames.Client.Photon.Hashtable infoJoueur = new ExitGames.Client.Photon.Hashtable();
//On instancie les infos sur son profil
infoJoueur.Add("type", "Rouge");
infoJoueur.Add("typePlayer", "player");
infoJoueur.Add("wantReplay", "Null");
PhotonNetwork.player.name = j.pseudo;
infoJoueur.Add("pseudo", j.pseudo);
PhotonNetwork.player.SetCustomProperties(infoJoueur);
GameObject profilR = PhotonNetwork.Instantiate(prefabProfilRouge.name, pivotRouge.transform.localPosition, Quaternion.identity, 0);
int view = profilR.GetComponent<PhotonView>().viewID;
GestionInteraction gi = profilR.GetComponent<GestionInteraction>();
gi.majInfoProfil(view,j.pseudo, victoireDefaite, panelAttenteMatchingJoueur);
} else { //we have the 2nd player
ExitGames.Client.Photon.Hashtable infoJoueur = new ExitGames.Client.Photon.Hashtable();
infoJoueur.Add("type", "Bleu");
infoJoueur.Add("typePlayer", "player2");
infoJoueur.Add("wantReplay", "Null");
PhotonNetwork.player.name = j.pseudo;
infoJoueur.Add("pseudo", j.pseudo);
PhotonNetwork.player.SetCustomProperties(infoJoueur);
PhotonPlayer[] listeJoueur = PhotonNetwork.playerList;
ExitGames.Client.Photon.Hashtable infoPlayerRouge = listeJoueur[0].customProperties;
ExitGames.Client.Photon.Hashtable infoPlayerRouge2 = listeJoueur[1].customProperties;
Debug.Log(infoPlayerRouge["type"].ToString() + " " + infoPlayerRouge2["type"].ToString());
Debug.Log(infoPlayerRouge["typeJoueur"].ToString() + " " + infoPlayerRouge2["typeJoueur"].ToString());
PhotonNetwork.room.open = false; //On ne peut plus accéder à la room
PhotonNetwork.room.visible = false; //La room n'est plus listée parmi la liste des room du lobby
}
}
When I get type in the type of the master client I got Rouge, and the type of client is Bleu.
The issue come when i make my two players leaves the room. The ancient client creates a new room and become the master client, and the previous master client joins the room as a client. But when i try to get the custom property type, sometimes i get "Bleu" or "Rouge" for both.
But normally it's not possible, because accoding to my previous code, master client and client doesn't execute the same code. This custom property is never modified in my app, so i don't know how they do to have the same custom property.
Please how could I do ?
The problem seems to be in the following lines of code
PhotonPlayer[] listeJoueur = PhotonNetwork.playerList;
ExitGames.Client.Photon.Hashtable infoPlayerRouge = listeJoueur[0].customProperties;
ExitGames.Client.Photon.Hashtable infoPlayerRouge2 = listeJoueur[1].customProperties;
PhotonNetwork.playerList is not the same for all clients. This means that index zero is not always the $$anonymous$$asterClient. You can check this by debug logging the playerList when there is just the $$anonymous$$asterClient and after another player joined the room.
I use these lines to check values in custom properties after the connection of the client. In the debug I got Red and Blue...But when I use the same lines of code somewhere in my app, I got Blue Blue or Red Red. That is to say that Photon changed these values automatically...
Your answer
![](https://koobas.hobune.stream/wayback/20220612082917im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Noob problem with Photon 0 Answers
Photon & Unity Question 0 Answers
Photon Network Client Reading empty variables when connect 0 Answers
Photon Join Random CustomRoomProperties not working 0 Answers