OnPlayerPropertiesUpdate is not called multiple times

I have this situation where a player has a CustomProperty ["x", true] (and for the second player, this property set to ["x", false]). At some point, I want to set this property to false for current player, and for the other player set it to true.

I have this snippet:
public void changeXproperty() {
            PunHashtable _myCustomProperties_forCurrentPlayer = new PunHashtable();
            _myCustomProperties_forCurrentPlayer["x"] = false;
            PhotonNetwork.PlayerList[0].SetCustomProperties(_myCustomProperties_forCurrentPlayer);

            PunHashtable _myCustomProperties_forNextPlayer = new PunHashtable();
            _myCustomProperties_forNextPlayer ["x"] = true;
            PhotonNetwork.PlayerList[1].SetCustomProperties(_myCustomProperties_forNextPlayer );
}
public override void OnPlayerPropertiesUpdate(Player targetPlayer, ExitGames.Client.Photon.Hashtable changedProps) {
            if (targetPlayer != null) {
                if (changedProps.ContainsKey("x")) {
                    foreach (Player player in PhotonNetwork.PlayerList) {
                            if ((bool)player.CustomProperties["x"] == true)
                            {
                                print("enters here 1");
                                // ... do something
                            }

                            if ((bool)player.CustomProperties["x"] == false) // the code only reach this if
                            {
                                print("enters here 2");
                                // ... do something
                            }
                        }
                }
            }
}

This code will never reach the enters here 1 code.. it's like the OnPlayerPropertiesUpdate is not called twice or something. How can I force a second call of this function? Thank you for your time!

I forgot to mention, if I check the `x` property of the players on a later moment in code, it is updated correctly for both players. But I need to do some action right away, not later.

Comments

  • I solved this by adding another OnPlayerPropertiesUpdate in another function. I don't know if this is a good practice, but for the moment it's working. Any suggestion is still welcome!
  • I did not debug this but if I recall correctly, the playerList is not sorted. So accessing it via the indexer might be wrong usage here.
    In addition to what you print now, also log the ActorNumber in all cases. As in: Which actorNumber does the player have, you set (and get) properties for?!