Is PhotonPlayer.CustomProperties persist after DC ?
Hi, is PhotonPlayer.CustomProperties persist after DC ? because i do a simple test to set int +1 CustomProperties and it is going well. But when I DC and reconnect to the room, the value return to null / 0 . is it the true ?
0
Answers
Thank you for choosing Photon!
I guess "DC" means disconnect ("DisConnect").
How do you leave and rejoin rooms?
To keep player properties between sessions, create rooms with PlayerTTL != 0.
Also use the appropriate leave and rejoin methods.
What SDK do you use? is it PUN?
Yes I mean Disconnected.
I just try a simple stop the Unity Editor and Start again. (Rejoin logic is handled by PhotonNetwork.CreateorJoinRoom)
Im using PUN with playerTTL set to 60000.
This is not the correct approach.
You should use unique UserID per user and persist that between sessions.
You should keep track of the rooms that player joined before and can still rejoin.
To rejoin either use:
-
ReconnectAndRejoin()
after unexpected disconnection-
Rejoin(roomName)
I just tested simple scene, not the actual game. Is it not sufficient enough and I need to use ReconnectAndRejoin?
Could you elaborate?
What did you test exactly?
I just installed PUN plugins on Unity 2017.3f so I still learn about how to use PUN. I want to store player score using player custom properties. what I already did was
1. Set PlayerTTL on RoomOptions to 60000 ms.
2. RoomTTL on RoomOptions to 3000 ms.
I save player score using PhotonNetwork.player.SetCustomProperties API and this is working great.
but when I quit the game (by stopping Unity Editor) and rejoin the room. my Score is lost. when I call
PhotonNetwork.player.CustomProperties, my Score properties is gone.
by the way about your previous comment,
You should use unique UserID per user and persist that between sessions.
You should keep track of the rooms that player joined before and can still rejoin.
what kind of UserID did you mean ? and is there any API that let us know that a room can still be rejoin ? is using PhotonNetwork.ReJoinRoom return value of boolean is enough to let us know that information ?
The UserID for a client can be set in three ways:
PhotonNetwork.AuthValues.UserId
before connecting.No. The lists of rooms to rejoin should be managed by you.
The only case supported out-of-the-box by PUN is the rejoin after unexpected disconnect as the room name is cached. So after an unexpected disconnect, you should call
PhotonNetwork0ReconnectAndRejoin()
. Of course, this could still fail in some cases (this is related to both PlayerTTL and EmptyRoomTTL).In general, if you want to rejoin a room by name, you should call
PhotonNetwork.ReJoinRoom(roomName)
. Of course, this could still fail in some cases (this is related to PlayerTTL, UserId and how/when you left the room in the first place).Thank you so much for the enlightment. I really appreciate that !
Is it safe for me to use unique ID that persist such as Steam UserID ? Im using Steamworks for this project. so it is nice if I had only 1 unique ID for player in my game.
So for me to know wether my reconnect fail or success the is Pun callback only ? such as OnPhotonJoinRoomFailed ? if that is the case, which PUN callback that i need to consider about when reconnecting and connection problem related (when game crash so no disconnecting logic running, sudden internet down etc)
Is it safe for me to use unique ID that persist such as Steam UserID ? Im using Steamworks for this project. so it is nice if I had only 1 unique ID for player in my game.
Successful connection:
-
-
Connection failure:OnConnectedToMaster()
OnJoinedLobby()
-
-
Disconnect callback:OnFailedToConnectToPhoton(DisconnectCause cause)
OnConnectionFail(DisconnectCause cause)
OnDisconnectedFromPhoton()
So for the summary. for a PhotonPlayer CustomProperties to persist after a Disconnect I need to use
Reconnect API ? wether ReconnectAndRejoin or RejoinRoom.
One more that bother me, when someone is disconnected with playerTTL > 0 (in my case 60 sec) the player object is still in the scene. Which is usually a game do ? let it be so when that player Reconnect so they will possess that player object again or should a MasterClient destroy Disconnected PlayerObject ? because in my game there's only 1 Instantiate logic when a player join a room, my game Instantiate an avatar for him.
and what happen when player Connect after playerTTL is reached. for example in my game when a player Reconnect after 60 sec. is it still possible to that player to retrieve his photonplayer CustomProperties ?
So if my players dc more than playerTTL value, I need to reassign his custom properties or what ? I mean currently I store player score in the player CustomProperties (Kill, death) just like any online FPS shooter. what should I do if the player dc longer than playerTTL ? should I store all of that data to Room Properties instead of player then ?
You want to keep player stats or profile or data between sessions and across matches.
You need to save this outside of Photon, maybe PlayFab or similar service.
No ! not accross matches. only in 1 match.
But I found a problem in this scenario
1. Game is started with playerTTL 60s.
2. Some player got DC because of internet problem / power outrage.
3. That player reconnect after more than 60s. for example after 5 min.
4. That player properties is gone now. (This is a problem because I store his score on this match on His PhotonPlayer.CustomProperties)
PlayerTTL = -1
EmptyRoomTTL = 300000.
What this mean is:
As long as the room is not empty, players can disconnect and rejoin without limitations.
A room can become empty for up to 5 minutes.