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 ?

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @metallizard,

    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?
  • Hi,

    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.
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2018
    Rejoin logic is handled by PhotonNetwork.CreateorJoinRoom

    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)
  • Hi Thanks for the reply.

    I just tested simple scene, not the actual game. Is it not sufficient enough and I need to use ReconnectAndRejoin?
  • JohnTube
    JohnTube ✭✭✭✭✭
    What do you mean?
    Could you elaborate?

    What did you test exactly?
  • metallizard
    edited January 2018
    Hi, Im sorry.

    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 ?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @metallizard,

    The UserID for a client can be set in three ways:
    1. Client sets PhotonNetwork.AuthValues.UserId before connecting.
    2. Returned by an external web service using Custom Authentication. It will override the value sent by the client.
    3. Photon will make up UserIDs (GUID) for users that don't explicitly set theirs.
    is there any API that let us know that a room can still be rejoin ?

    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).
    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 ?
    All Photon operations are asynchronous, the client sends a request to the server and in most cases receive a response. So the operation methods return a boolean to indicate that the request could be sent and not that the operation has ended or succeeded.

    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).
  • Hi @JohnTube

    Thank you so much for the enlightment. I really appreciate that !

    Client sets PhotonNetwork.AuthValues.UserId before connecting.

    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.

    All Photon operations are asynchronous, the client sends a request to the server and in most cases receive a response. So the operation methods return a boolean to indicate that the request could be sent and not that the operation has ended or succeeded.

    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)
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2018
    Hi @metallizard,

    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.
    Not only is this safe, but it's recommended!
    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)
    You can get all callback names in different ways. For instance, they are listed in IPunCallbacks interface. The ones you are looking for in this case are:

    Successful connection:
    • OnConnectedToMaster()
    • OnJoinedLobby()
    Connection failure:
    • OnFailedToConnectToPhoton(DisconnectCause cause)
    • OnConnectionFail(DisconnectCause cause)
    Disconnect callback:
    OnDisconnectedFromPhoton()
  • metallizard
    edited January 2018
    Hi Thank you for the answer ! Really help a lot !

    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 ?
  • JohnTube
    JohnTube ✭✭✭✭✭
    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.
    This is up to you, try both options. There are some forum discussions regarding this, I don't have the links now or remember which ones, you could try the search feature in the forum.

    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 ?
    No it's not possible. The actor will be removed from the room with all its properties.
  • Hi @JohnTube Thanks for the reply. !

    No it's not possible. The actor will be removed from the room with all its properties.


    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 ?
  • JohnTube
    JohnTube ✭✭✭✭✭
    I see now.
    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.
  • Hi @JohnTube

    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)
  • JohnTube
    JohnTube ✭✭✭✭✭
    Here is what I think you should try:

    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.