Joining an empty room, the scene objects lose their serialized PhotonView state

Options
I'm building a multiplayer game, where I have lots of PhotonViews that are created with PhotonNetwork.InstantiateSceneObject(...) and the state is synchronized with OnPhotonSerializeView(...) between clients, which works wonderful if at least 1 player is in the room.

I want to support (re)joining an empty room that has no user. The most common use case is that a player loses it internet connection for a split second and wants to rejoin. Or when the browser / app crashes so that he can continue playing. For this I set RoomOptions.EmptyRoomTtl to 60000 miliseconds.

The issue I'm currently having is that the serialized state gets lost. All the scene object gets created but OnPhotonSerializeView() is not called. Not until a second player joins, but then PhotonStream.IsWriting is obviously true, which does not help, since the master client doesn't know the state.

I was hoping OnPhotonSerializeView() would get called, when joining the empty room as master client, so that the last synchronized state could be recovered.

I tried several things:
- RoomOptions.CleanupCacheOnLeave = false
- this.photonView.Synchronization = ViewSynchronization.Off;
- A lower PlayerTTL (10 seconds) then EmptyRoomTtl (60 seconds)
- Getting the last synchronized state from inside the parameter of OnPhotonInstantiate(PhotonMessageInfo info) callback

Other Infos:
- I'm using Unity 2018.2.20 and PUN v2.6 (Photon lib 4.1.2.7)
- I'm currently testing in the Unity Editor and a standalone build on macOS.

I found some forum thread around my issue (EmptyRoomTtl and OnPhotonSerializeView), but i don't see any leads to resolve my issue:
- http://forum.photonengine.com/discussion/11003/frequent-disconnects-and-rejoin
- https://forum.photonengine.com/discussion/11219/reconnectandrejoin-when-youre-the-last-player-in-the-room
- https://forum.photonengine.com/discussion/10105/pun-reconnect-player-actorid

Can somebody give me a clue how to recover my serialized PhotonView state?

Answers

  • Tobias
    Options
    I'm sorry to say but the server does not keep the most recent state of individual objects, so a rejoin of the last player is not supported by the server.
    You might be able to store the state locally and when you rejoin an empty room, you'd apply this. A client who would rejoin the empty room is the Master Client anyways and has authority. Until a second player joins, the room does not get updated (as the authority is guaranteed to be local anyways).

    Without a server plugin, there is no simple way to make the server keep updates of objects.
  • JeanLuc
    Options
    Thanks for the confirmation, of what I was suspecting, that the data is not stored in the photon cloud.

    I'm evaluating to restore the local game state and check how to handle the edgecases.