PUN reconnect / player actorID
The whole answer can be found below.
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).
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
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
orRoomOptions.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
orint.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.
Perfect!
This means I did something wrong and the player was not rejoining, he was entering the room again.
Ty for detailed answer.