Photon user objects destroyed on disconnect

I want to stop photon from destroying the user instantiated gameobjects when the user disconnects so that on reconnect they are still there.

Comments

  • TobiasTobias admin
    This is tricky, as there will be two versions of the object while the player is not connected: The one on said player's client and the one in the room. While someone is away, the object is put under control of the Master Client, so it may move and you have to somehow rearrange which state of the object is the correct one, when someone rejoins.

    Overall, the RoomOptions.CleanupCacheOnLeave setting should be the one you need to not destroy objects on leave.
  • I did use the RoomOptions.CleanupCacheOnLeave. Still when the player disconnected, the gameobjects got destroyed. I'm able to reconnect using reconnectandjoin(). These are the room option settings:
    byte maxPlayers = (byte)MaxPlayersPerRoom;
    string roomName = "Room" + Random.Range(0, 10000);
    RoomOptions roomOptions = new RoomOptions();
    roomOptions.PlayerTtl = 60000;
    roomOptions.EmptyRoomTtl = 60000;
    roomOptions.MaxPlayers = maxPlayers;
    roomOptions.PublishUserId = true;
    roomOptions.IsOpen = true;
    roomOptions.IsVisible = true;
    roomOptions.CleanupCacheOnLeave = false;
    PhotonNetwork.CreateRoom(roomName, roomOptions);
  • TobiasTobias admin
    edited June 3
    Which version of PUN 2 do you use?
    Will try to repro and provide some help.
  • TobiasTobias admin
    So, PhotonHandler.OnLeftRoom() will call LocalCleanupAnythingInstantiated unconditionally, which does the cleaning up.

    The idea was to clean up objects in case you want to rejoin the room. Then, lingering objects would clash with their "originals" from within the room and you'd need to clarify which ones to keep, where everything is and who has control. When you rejoin the room, the objects get re-instantiated again and this would clash.

    So, you can modify the PhotonHandler to not clean up. Then you'd have to clean up before you rejoin (if you do).

    We could change the behavior for this but are unsure if we want to introduce this breaking change...

    Let me know if this helps you find all necessary code to make your variant work.
  • I'm using PUN 2.24 Photon lib: 4.1.4.7. I will look into what you said, thanks.
  • TobiasTobias admin
    I would update to the latest PUN 2, by the way. Avoids hunting down bugs that may be fixed more recently.
Sign In or Register to comment.