PUN reconnect / player actorID

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

PUN reconnect / player actorID

Bonzy
2017-06-21 11:28:52

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.

Comments

JohnTube
2017-06-21 12:03:12

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.

Bonzy
2017-06-21 12:56:23

Perfect!
This means I did something wrong and the player was not rejoining, he was entering the room again.
Ty for detailed answer.

Back to top