Pun 2 + Unity

Hi All,

I'm new to networking and am trying out PUN 2. However, I'm stuck between syncing states between newly joined players with current state of the room.

Reading the documentation and if I understand correctly, there are two ways I can load the current game state properly for a newly joined player. Either with RPC Calls with buffers, or CustomProperties. 

I did not choose to go along with RPC method because my application might have a long linear state which having large amounts of RPC Buffers collected and loaded for new players might not be optimal.

I manage to get the CustomProperties method to work, however, when calling from CustomProperties from Start() method gives me null error, which I assume is due to the client having to take some time to retrieve the global CustomProperties to their local state in order to read, because I tried waiting a couple of second before enabling to object which successfully reflects the current state of the room in their client.

So my issue is that I cannot seem to find a method in the documentation that triggers when the CustomProperties is fully retrieved from the server. The closest I can find is "OnRoomPropertiesUpdate" which does not trigger when the data is loaded since start, but only triggers when updates are being done real-time.

Hopefully I can get some help as I'm wrecking my brains here.

Best Answer

  • Tobias
    Tobias admin
    Answer ✓

    You can use OnJoinedRoom. When it's called, you got the properties for the first time.

    Let us know if there are other questions.

Answers

  • Tobias
    Tobias admin
    Answer ✓

    You can use OnJoinedRoom. When it's called, you got the properties for the first time.

    Let us know if there are other questions.

  • It worked, thanks!