Room.SetCustomProperties()/ Room.OnRoomPropertiesUpdate()

Options
Hi, and my apologies that this is a newbie question about PUN.

It seems that whenever i call Room.SetCustomProperties(), i will also get Room.OnRoomPropertiesUpdate() called on my own process in addition to the other processes.

Clearly the whole point of room custom properties is to communicate with the other processes, but it seems it would be helpful to be able to distinguish between changes that my local process is initiating (for which I don't need notification), versus changes made by other processes (which i clearly need).

Are there any flags or alternate ways to call Room.SetCustomProperties() without notifying myself with OnRoomPropertiesUpdate()

Thanks again, and apologies if this is covered elsewhere

Best Answer

  • JohnTube
    JohnTube ✭✭✭✭✭
    Answer ✓
    Options
    Hi @bermondo,

    Thank you for choosing Photon!

    BroadcastPropertiesChangeToAll can be set during room creation via RoomOptions.
    By default, setting properties for actor or room properties will not take effect on the sender/setter client (actor that sets the properties) immediately when joined to an online room unlike what it used to be in PUN Classic. Now, instead, the sender/setter client (actor that sets the properties) will wait for the server event PropertiesChanged to apply/set changes locally. So you need to wait until OnPlayerPropertiesUpdate or OnRoomPropertiesUpdate callbacks are triggered for the local client in order to access them. The new behaviour is due to the introduction of the new room option flag roomOptions.BroadcastPropsChangeToAll which is set to true by default. The reason behind this is that properties can easily go out of synchronization if we set them locally first and then send the request to do so on the server and for other actors in the room. The latter might fail and we may end up with properties of the sender/setter client (actor that sets the properties) different locally from what's on the server or on other clients. If you want to have the old behaviour (set properties locally before sending the request to the server to synchronize them) set roomOptions.BroadcastPropsChangeToAll to false before creating rooms. But we highly recommend against doing this.
    source

Answers

  • bermondo
    Options
    I see the BroadcastPropertiesChangeToAll flag defined as a get (but not settable) flag. Looking at the source code, it appears that it can only be set through an internal function InternalCacheRoomFlags(int roomFlags) using bit flags that are deep inside LoadbalancingPeer.

    1) is this the correct flag to use?
    2) is there a way for my application to set it?

    Thanks
  • JohnTube
    JohnTube ✭✭✭✭✭
    Answer ✓
    Options
    Hi @bermondo,

    Thank you for choosing Photon!

    BroadcastPropertiesChangeToAll can be set during room creation via RoomOptions.
    By default, setting properties for actor or room properties will not take effect on the sender/setter client (actor that sets the properties) immediately when joined to an online room unlike what it used to be in PUN Classic. Now, instead, the sender/setter client (actor that sets the properties) will wait for the server event PropertiesChanged to apply/set changes locally. So you need to wait until OnPlayerPropertiesUpdate or OnRoomPropertiesUpdate callbacks are triggered for the local client in order to access them. The new behaviour is due to the introduction of the new room option flag roomOptions.BroadcastPropsChangeToAll which is set to true by default. The reason behind this is that properties can easily go out of synchronization if we set them locally first and then send the request to do so on the server and for other actors in the room. The latter might fail and we may end up with properties of the sender/setter client (actor that sets the properties) different locally from what's on the server or on other clients. If you want to have the old behaviour (set properties locally before sending the request to the server to synchronize them) set roomOptions.BroadcastPropsChangeToAll to false before creating rooms. But we highly recommend against doing this.
    source