OnPlayerPropertiesUpdate not called?

I am just beginning with PUN (porting a project using UNET). Everything has worked great so far (well not far yet).
But for the life of me I can't figure out when I set Player custom property the OnPlayerPropertiesUpdate is not called.

I am setting the properties as follows:

Hashtable hash = new Hashtable();
hash["driver"] = driver; //driver is int value
player.SetCustomProperties(hash);
But on my other class (which inherits MonoBehaviourPunCallbacks) the method is not getting called:

public override void OnPlayerPropertiesUpdate(Player target, Hashtable changedProps)
{
Debug.Log("MPLobbyPlayer: OnPlayerPropertiesUpdate() " + changedProps.ToString());
if (target == photonView.Owner && changedProps.ContainsKey("driver")) {
RefreshNameAndDriver();
}
}
Am I missing extra steps here? I can verify on the masterclient (where I set the custom properties) that the properties are actually getting set. Just the callback is not called. I've understood the OnPlayerPropertiesUpdate() should be automatically called even on the client that is calling SetCustomProperties(), right?

Comments

  • Hi @zilp,

    Thank you for choosing Photon!

    Yes, what you have reported (OnPlayerPropertiesUpdate "not automatically called on the client that is calling SetCustomProperties()" but should be triggered for the others) is the actual behaviour. We will discuss internally if it should be the correct or intended behaviour or not.

    Here are few things to try however:

    1. Verify RoomOptions.BroadcastPropsChangeToAll is set to true when you create rooms. This will enable sending the PropertiesChanged event to everyone inside the room including the player whose properties have changed or the one who made the change. This is supported on the Photon Cloud only for now and not on the self-hosted Photon Server.
    2. Use CAS ("Check-And-Swap" or "Compare-And-Set") feature using Expected Properties if possible. This will also trigger a PropertiesChanged event broadcast to everyone inside the room in case of success.

    The difference between 1 and 2, in the current code base:

    1. will set the custom properties locally before making the call to the server.
    2. will not set any properties locally until getting ack/confirmation/order/event from the server.
  • Upon further inspection, the OnPlayerPropertiesUpdate is indeed called on other MonoBehaviourPunCallbacks objects.
    The one where it is not called is the one I have attached to a prefab and which instantiate when OnJoinedRoom() gets called:
    PhotonNetwork.Instantiate(this.lobbyPlayerPrefab.name, new Vector3(0f,5f,0f), Quaternion.identity, 0);

    This prefab has the PhotonView component and a custom component which inherits the MonoBehaviourPunCallbacks. For some reason for this custom component the OnPlayerPropertiesUpdate does not get called.
  • @JohnTube do you have insight on if I am supposed to something else for when instancing prefabs with MonoBehaviourPunCallbacks - for them to actually get the callbacks? Or is this something I should not be doing? I can of course work around this issue by refreshing these components my self from the manager class (which has the OnPlayerPropertiesUpdate() call working properly). But I'd like to verify this is expected behaviour?

    Also, in the PUN2 documentation for OnPlayerPropertiesUpdate
    "Changing properties must be done by Player.SetCustomProperties, which causes this callback locally, too."
    http://doc-api.photonengine.com/en/pun/v2/class_photon_1_1_pun_1_1_mono_behaviour_pun_callbacks.html#details
  • @JohnTube ok - this was super stupid of me :dizzy:

    I had infact overwritten the OnEnable() method on my subclass, without calling base.OnEnable(); - Not realising that there was actually implementation in MonoBehaviourPunCallbacks that was setting the PhotonNetwork.AddCallbackTarget(this);

    So problem solved :)
Sign In or Register to comment.