Can't set the custom properties of a player

Options
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:

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!

Best Answer

  • JohnTube
    JohnTube ✭✭✭✭✭
    Answer ✓
    Options
    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.

Answers

  • S_Oliver
    S_Oliver ✭✭✭
    edited April 2020
    Options

    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.

  • NaBUru38
    Options
    Oh, I see. But I can't find OnPlayerPropertiesChanged() anywhere on the documentation, except on the C++ side.
  • NaBUru38
    Options
    Do you mean OnPlayerPropertiesUpdate() at MonoBehaviourPunCallbacks?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Answer ✓
    Options
    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.