Custom room property for remote player/client always returns null
Options
Hie. I'm trying to retrieve a value from the server. From my understanding player custom properties are sync to the server which makes them accessible to any other payer/client who needs them. In my case I'm trying to retrieve a value from a remote player and the returned value is always null.
Here is my logic for creating custom properties for each player. This logic is called in the start function of my GameManager script.
Here is my logic for creating custom properties for each player. This logic is called in the start function of my GameManager script.
//set the custom properties for this player PhotonNetwork.player.CustomProperties = new Hashtable(); PhotonNetwork.player.CustomProperties.Add("Turns", 0);There is some logic in between up to the point where I need to retrieve the value of the remote player. Here is the logic throwing a null reference error.
MatchManager.Instance.OppTurns = (int) PhotonNetwork.player.GetNext().CustomProperties["Turns"];Just to clarify that the problem is with the remote player custom properties. I added some logic to verify this before my actual logic and here it is.
Debug.Log(PhotonNetwork.player.CustomProperties.ToString());//prints out the property Debug.Log(PhotonNetwork.player.GetNext().CustomProperties.ToString()); //throw a null reference errorCan someone assist me on how I can successfully sync the custom property to the server and retrieve for an player local or remote. Thank you.
0
Best Answer
-
Hi @Wasu_Studio_01,
the Custom Player Properties are synchronized automatically across all clients in the same room.
You can access the local player by usingPhotonNetwork.player
and his properties by usingPhotonNetwork.player.CustomProperties
. You usually don't have to use the new keyword on them and should avoid modifying them directly. Instead you should use thePhotonNetwork.player.SetCustomProperties
function.
To get the properties of an remote player, you can use the player list in the room, in this case only the list which contains the other players. This array can be accessed by usingPhotonNetwork.otherPlayers
. To get the properties of a certain player you can usePhotonNetwork.otherPlayers[index].CustomProperties[...];
.5
Answers
-
Hi @Wasu_Studio_01,
the Custom Player Properties are synchronized automatically across all clients in the same room.
You can access the local player by usingPhotonNetwork.player
and his properties by usingPhotonNetwork.player.CustomProperties
. You usually don't have to use the new keyword on them and should avoid modifying them directly. Instead you should use thePhotonNetwork.player.SetCustomProperties
function.
To get the properties of an remote player, you can use the player list in the room, in this case only the list which contains the other players. This array can be accessed by usingPhotonNetwork.otherPlayers
. To get the properties of a certain player you can usePhotonNetwork.otherPlayers[index].CustomProperties[...];
.5