Not connecting back to master after calling ConnectToRegion

Hi!
I've been having some issues with changing regions in-game.

Want to allow users to choose their region in the game and when they do we disconnect them (from connection that is actually on master and "connectedAndReady", wait for disconnect to be finished, then call PhotonNetwork.ConnectToRegion.
The connection gets to the point off Connected to name server (which i find when I debug.log PhotonNetwork.connectionStateDetailed.ToString() even up to minutes later it always says ConnectedToNameServer)
Which obviously wont let me create or join rooms as it says: CreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.

Have tried resetting authvalues as well and this didn't work.

Thanks!!

Comments

  • Hi @simone_unleashed,

    Want to allow users to choose their region in the game and when they do we disconnect them (from connection that is actually on master and "connectedAndReady", wait for disconnect to be finished, then call PhotonNetwork.ConnectToRegion.


    I don't get why you establish a connection first, then disconnect and connect again. Is there any reason for this? Besides that, the described application flow looks good as far as I can see. Have you already tried connecting to a certain region without the first connect and disconnect?
  • We don't want to force the user to choose a region every single time so we connect them to a default one (or what they chose last time, stored in player prefs) and give them the option in the settings menu to change if they need to (bad connection, wanting to connect with someone in a diff region etc).

    If I remove initial connection and then use ConnectToRegion it works and joins me to that region, so it seems to be a problem with disconnecting then connecting. Is there any way around this or to make it work? I'd rather not ask the user to restart the app every time they change regions.

    Thanks
  • Have temporarily asked player to restart the app if they change region and on start it connects them to whatever region they previously chose as saved in playerprefs (or a default one if they havent chosen yet).

    Ideally disconnecting and connecting to different server should work though? Any word on what I can do to get it to work in the future??
  • Can you show the source code you are using for connecting and disconnecting? I don't have any problems connecting to a certain region, disconnect from it and connect to another region.
  • So this is if it's their first time or they've never set the region before:

    PhotonNetwork.autoJoinLobby = true;
    PhotonNetwork.automaticallySyncScene = true;
    PhotonNetwork.logLevel = Loglevel;

    if(PhotonNetwork.connected == false)
    {
    if (!PlayerPrefs.HasKey("Region"))
    {
    PhotonNetwork.ConnectUsingSettings(gameVersion);
    }
    }">

    And this is if they have a region set, which all works it just gets to connected to nameserver and stalls
    public void ChangeServer(CloudRegionCode _newCode)
    {
    PhotonNetwork.Disconnect();
    PhotonNetwork.AuthValues = new AuthenticationValues();
    PhotonNetwork.AuthValues.UserId = PhotonNetwork.player.UserId;
    PhotonNetwork.ConnectToRegion(_newCode, gameVersion);
    }"


    Which works fine when its called from start without first connecting, but when its called later on when the user is already connected it doesn't work :/
  • The problem is, that you are calling Disconnect and Connect right after each other, which won't work as far as I know. After calling Disconnect, you have to wait for the void OnDisconnectedFromPhoton() callback. After this one is called, everything is reset and the client is ready to connect again.

    It works fine the first time, because the client haven't been connected and he is in his 'default' disconnected state.
  • I have tried doing the connect on onDisconnectedFromPhoton and still had the same issue actually, so unfortunately its not that :(
  • Can you try to remove the AuthValues before connecting again (just comment out both lines) and see if it works afterwards?

    Hint: according to the comment in the source code, PhotonNetwork.player.UserId is "available when the room got created [...]."