Search Unity

Help Wanted Photon ReconnectAndRejoin does "nothing"

Discussion in 'Multiplayer' started by Olipool, Oct 18, 2020.

  1. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    155
    Hi all,

    I read a bit about how to handle disconnects and rejoining a game and I think I understand the concept but when I tried to implement it, the behavior is unexpected...

    I am connecting, creating a room with TTLs of 60 seconds for the player and the room, and once in there, I spawn my avatar. Then I disconnect my internet and wait a few seconds. Then my avatar disappears and OnDisconnect gets called with the reason "ClientTimeout".

    I have a button that calls ReconnectAndRejoin() and when I use it, the result of the method is true but nothing else happens. No callback is called and when I looked in the source code the method only connects to the "ServerConnection.GameServer", but I can't see a call to RejoinRoom(string roomName) at all (maybe it is hidden in the dlls?).

    I have to add, that isConnected is false before the call so does that mean I am also disconnected from the master server? I then tried using simply "Reconnect()" without the Rejoin and that connected me to the master server and called the callback OnConnectedToMaster.

    Of course, I could save the room name and if it is a reconnect and then call RejoinRoom in OnConnectedToMaster, but as far as I understand ReconnectAndRejoin would do all of that in one go? When else should I use that method? Am I not getting the concept right?

    Thanks a lot in advance, this multiplayer thing is killing me :D
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,686
    Which PUN version do you use?

    You are "creating a room with TTLs of 60 seconds". I hope this means you set the PlayerTTL = 60000?
    Afaik, there is no callback "RejoinRoom(string roomName)", so I wonder what you do here.
    Depending on your game's logic, maybe the scripts called RemoveCallbackTarget() and no longer get callbacks at all?
     
  3. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    155
    Sorry for omitting the version, the changelog says v2.19.3.

    Yes, I am using 60000 milliseconds. And RejoinRoom(string roomName) is no callback but a method in PhotonNetwork.cs. And that is not called, at least not when I debugged it step by step, when I am calling ReconnectAndRejoin(). It only tries to connect to the GameServer (versus MasterServer if I just use Reconnect()).

    So in short:
    calling ReconnectAndJoin() results to true but isn't calling any callback
    calling Reconnect() calls the OnConnectedToMaster callback

    So the first one should at least call OnJoinedRoom but I don't see any logic rejoining a room in that.
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,686
    Make sure you set roomOptions.PlayerTtl in every place which creates a room (this is a frequent problem I ran into, where CreateRoom gets called in various situations with differing settings). The EmptyRoomTTL is not relevant here.

    Increase the logging level and enable the SupportLogger in the settings, to get an overview of what happens.

    I just checked in v2.22 and that worked. I don't see changes / fixes that affect this since 2.19.3.
     
  5. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    155
    Thanks, the logging hint is really nice, I love lots of logging :)
    Seems you are right, the support loggers says:

    SupportLogger OnJoinRoomFailed(-3,Room does not support rejoing. PlayerTTL is 0)

    I have to look into that though I don't know where the TTL is set to 0.
    MAYBE it has to do with the fact, that on disconnect I go into offline mode so the player can continue solo and by that he is joining an offline room? And when he presses the rejoin button he is set to online mode and maybe the rejoin tries to join the offline room again...
    By the way if I call the rejoin directly in OnDisconnected and I am still without internet, does OnDisconnected called again after a while? Or do I have to store the result (false) of the rejoin and set a timer to try again?

    Thanks again! :)
     
  6. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    155
    Oh, it is really so stupid...
    The room was indeed created with PlayerTTL of -1 but I did not see it because in my code the PlayerTTL on top of my script was initialized with 60000. BUT it is public so it is exposed in the inspector and there it was still -1 and Unity favors the inspector over the code in that case. Sorry for having bothered you with such a noob mistake ;)

    Right now it works, but somehow the spawning of the player seems to get called twice (I use an RPC for the instantiation and on disconnect, the avatar is gone, so after rejoin it has to be called more than once):
    PhotonView ID duplicate found: 1001. New: View 1001 on PlayerAvatar00(Clone) old: View 1001 on PlayerAvatar00(Clone) . Maybe one wasn't destroyed on scene load?! Check for 'DontDestroyOnLoad'. Destroying old entry, adding new.

    But that is another issue and I will try to sort it out first on my own. Thanks again! :)
     
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,686
    If ConnectUsingSettings() returns true, then yes, PUN may call OnDisconnected if the connection is not possible yet.

    Hehe. I know that case. You'll see comments "// set in inspector" in my code to remind myself.

    Glad you found it.

    The RPC is likely buffered. You may get this from the server again and should not execute the "on joined" initialization on top of this.
     
  8. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    155
    Good idea with the comments :)
    Yes, I buffer RPCs, thanks, I will put all your advice given here to good use!
     
unityunity