Can't set the custom properties of a player
Options
NaBUru38
✭
Hello, I'm trying to use custom properties for a player, but I can't make them work.
My current codes looks something like this:
Any suggestions? Thanks!
My current codes looks something like this:
if (PhotonNetwork.IsConnected) { PhotonHashtable hostProperties = new PhotonHashtable (); hostProperties.Add (someProperty, someValue); bool hasDefinedKey = hostProperties.ContainsKey (someProperty); //true bool hasSetKey = PhotonNetwork.LocalPlayer.SetCustomProperties (hostProperties); // true bool hasFoundKey = PhotonNetwork.LocalPlayer.CustomProperties.ContainsKey (someProperty); // false !!! }
Any suggestions? Thanks!
0
Best Answer
-
Hi @NaBUru38,
Thank you for choosing Photon!
First you should replaced PhotonNetwork.IsConnected check with PhotonNetwork.InRoom. It's the more appropriate condition for trying to set properties.
Second thing, as @S_Oliver mentioned, we changed/fixed the behaviour in PUN 2.17.
So to make the code snippet above work (old behaviour), set roomOptions.BroadcastPropsChangeToAll to false when creating rooms.
However now we recommend keeping default new behaviour and properties are set after callbacks are fired like OnPlayerPropertiesUpdate yes.2
Answers
-
What version do you got? Is it the newest? If I remember correct they changed the property behaviour slightly.
On the newest version they send the properties ,before setting/receiving locally.
Nevertheless since its networking and async better work with the callback OnPlayerPropertiesUpdate .
Reading directly after setting doesn't work, relay on the callback, since it has to be synchronised to all clients.
0 -
Oh, I see. But I can't find OnPlayerPropertiesChanged() anywhere on the documentation, except on the C++ side.0
-
Do you mean OnPlayerPropertiesUpdate() at MonoBehaviourPunCallbacks?0
-
Hi @NaBUru38,
Thank you for choosing Photon!
First you should replaced PhotonNetwork.IsConnected check with PhotonNetwork.InRoom. It's the more appropriate condition for trying to set properties.
Second thing, as @S_Oliver mentioned, we changed/fixed the behaviour in PUN 2.17.
So to make the code snippet above work (old behaviour), set roomOptions.BroadcastPropsChangeToAll to false when creating rooms.
However now we recommend keeping default new behaviour and properties are set after callbacks are fired like OnPlayerPropertiesUpdate yes.2