when i first enter a Room i locally store the LocalPlayer() info… this has a unique UserId … and i give every other Player this UserId to identify me… this works really well…
.
HOWEVER… if i then get the PlayerList() for the Room… the UserId for this list seem to NOT match the UserId each got when first created… this is… it can’t find UserId’s of the others based on this mechanism… (i’m not sure… but seems to identify its own UserId this way)…
.
what i was trying to do is write a ‘disconnect watchdog’… it would compare it’s list of all the Player’s local UserId list with the User Id’s of the PlayerList() to see if it was missing and remove it from each remaining Player’s UserId lists… but it can’t find any of the other Player’s UserId’s in the PlayerList()…
.
so what should i look at or study to deal with another Player disconnecting unexpectedly… that is… things like internet loss or power failures at other Player’s end?
First off: The Player.NickName
and UserId
are not the same. One can be used as display name, the other identifies an account (as long as you also use Authentication).
The UserId is not distributed, unless you set the relevant flag when you create the room: RoomOptions.
PublishUserId.
PUN will call a callback when someone leaves. It provides the Player object of the user who leaves, so I think you do not really need your own watchdog.
thanks!.. does this leaving callback gets called even if it’s an unplanned disconnect… (such as an internet problem or a power outage at the leaving Player’s end)?
Yes, when someone else loses connection, the remaining players will notice this via the callback (after a timeout time).
cool!.. thanks!
got a question though… how can one tell WHICH player dropped out?.. especially since even if it returns the PHOTON ‘Player’ we already know the ‘UserId’ and ‘Nickname’ can’t be used to identify it!
In the room, the ActorNumber
is the “id” of each player.
Globally, use the userID
. You can make the server send it, if you want to use it…
Both would be available in OnPlayerLeftRoom(Player otherPlayer)
.