How to monitor just a specific custom property for OnPlayerPropertiesUpdate?

Options

Hello, I wanted to send an RPC every time a specific custom property of the local player is updated. I implemented OnPlayerPropertiesUpdate() but this tracks every update on every custom property, hence the the RPC is called even if the custom property updated is not related to the RPC that will be sent. Is there a way to discriminately track updates on specific custom property? thanks!


This is the OnPlayerPropertiesUpdate I used:

   public override void OnPlayerPropertiesUpdate(Player targetPlayer,ExitGames.Client.Photon.Hashtable changedProps)
  {
    Invoke("RPCCall", 2.0f);
  }


  void RPCCall()
  {
    int registeredTeam  = (int)PhotonNetwork.LocalPlayer.CustomProperties["playerTeam"];
    PhotonView pv =  GameObject.Find("CharacterSelectionManager").GetComponent<PhotonView>();
    pv.RPC("RecievedString", RpcTarget.All, registeredTeam.ToString());
  }

This is then received on another script:

    [PunRPC]
    void RecievedString(string str, PhotonMessageInfo info)
    {
        tempHold = str;
        if (tempHold == "0")
        {
            Debug.Log(info.Sender + "Joined Blue Team");
        }
        if (tempHold == "1")
        {
            Debug.Log(info.Sender + "Joined Red Team");
        }
    }


Best Answer

  • Tatsuki
    Tatsuki
    edited March 2022 Answer ✓
    Options

    I invoked a function from the OnPlayerPropertiesUpdate. This function checks whether the specific customprop I am interested in is changed or not. if it is changed, then a variable lock is changed. once the lock is changed OnPlayerPropertiesUpdate will also fire the RPCCall, firing the RPCCall will also reset the lock. Roundabout way of doing it but it works for me. I'd like to remove this question but I can't/don't know how so I guess I'll just leave this here. If there is a more efficient method, I'd love to hear it! Cheers.

Answers

  • Tatsuki
    Tatsuki
    edited March 2022 Answer ✓
    Options

    I invoked a function from the OnPlayerPropertiesUpdate. This function checks whether the specific customprop I am interested in is changed or not. if it is changed, then a variable lock is changed. once the lock is changed OnPlayerPropertiesUpdate will also fire the RPCCall, firing the RPCCall will also reset the lock. Roundabout way of doing it but it works for me. I'd like to remove this question but I can't/don't know how so I guess I'll just leave this here. If there is a more efficient method, I'd love to hear it! Cheers.

  • Tobias
    Options

    Well, there is kind of an answer for this, so the thread can just stay for reference.

    Thanks for the update. Glad you found a solution.