PUN reconnect / player actorID

Hello,
Another question about reconnect:
From what i understand, the PhotonPlayer ID gets changed on player rejoin and you can do the reconnect in 2 ways:
- easy : ReconnectAndRejoin function
- harder: keep name of room and old player ID and connect to Photon on disconnect then connect to the same room passing the old player ID also.

Is there any way to keep the same player ID on reconnect?

So far I think I need to send a RPC after the reconnect to tell my old ID to the other players in the room but was curious if there is a way to know this is that user that disconnected without needing another RPC call.

Thanks.

Best Answer

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited June 2017 Answer ✓
    Hi @Bonzy,

    Photon keeps same Actor Number (in PUN it's called Player ID) when you rejoin properly.
    To rejoin properly:
    - Use/re-use unique UserIDs.
    - Set RoomOptions.CheckUserOnJoin = true when you create rooms (should be the case by default for PUN if not hidden already)
    - Set RoomOptions.PlayerTTL > 0 or RoomOptions.PlayerTTL = -1 when you create rooms. PlayerTTL is how long the player can stay inactive inside the room. An actor becomes inactive inside the room when it disconnects from it without leaving it for good and PlayerTTL != 0. -1 or int.MaxValue mean actor never time out and can stay inactive inside the room forever.
    - Call Rejoin with room name within PlayerTTL milliseconds from deactivation time. Deactivation time is when actor became inactive inside the room.
    - If room becomes empty it will be destroyed after RoomOptions.EmptyRoomTTL. A room is considered empty when there is no active actor left. A maximum value allowed for EmptyRoomTTL on public cloud is 300000 milliseconds (5 minutes). If you want to rejoin after that you need to persist room state to be able to save it and load it. We offer webhooks as a solution for this. Otherwise you may get "GameDoesNotExist" error.

    ReconnectAndRejoin is a special shortcut in PUN. The above applies to it as well.

    - harder: keep name of room and old player ID and connect to Photon on disconnect then connect to the same room passing the old player ID also.
    This approach is deprecated. If you still need it passing -1 (or anything != 0) should work.

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited June 2017 Answer ✓
    Hi @Bonzy,

    Photon keeps same Actor Number (in PUN it's called Player ID) when you rejoin properly.
    To rejoin properly:
    - Use/re-use unique UserIDs.
    - Set RoomOptions.CheckUserOnJoin = true when you create rooms (should be the case by default for PUN if not hidden already)
    - Set RoomOptions.PlayerTTL > 0 or RoomOptions.PlayerTTL = -1 when you create rooms. PlayerTTL is how long the player can stay inactive inside the room. An actor becomes inactive inside the room when it disconnects from it without leaving it for good and PlayerTTL != 0. -1 or int.MaxValue mean actor never time out and can stay inactive inside the room forever.
    - Call Rejoin with room name within PlayerTTL milliseconds from deactivation time. Deactivation time is when actor became inactive inside the room.
    - If room becomes empty it will be destroyed after RoomOptions.EmptyRoomTTL. A room is considered empty when there is no active actor left. A maximum value allowed for EmptyRoomTTL on public cloud is 300000 milliseconds (5 minutes). If you want to rejoin after that you need to persist room state to be able to save it and load it. We offer webhooks as a solution for this. Otherwise you may get "GameDoesNotExist" error.

    ReconnectAndRejoin is a special shortcut in PUN. The above applies to it as well.

    - harder: keep name of room and old player ID and connect to Photon on disconnect then connect to the same room passing the old player ID also.
    This approach is deprecated. If you still need it passing -1 (or anything != 0) should work.
  • Perfect!
    This means I did something wrong and the player was not rejoining, he was entering the room again.
    Ty for detailed answer.