Photon not rejoining Master Server after leaving room

Hi, I'm having an issue where Photon Network doesn't appear to rejoin the Master Server after leaving a room.

In our game, we switch between online and offline modes. This involves changing to a transition (loading) scene, which asynchronously loads the main scene, connects to photon if not connected and joins a room.

The scenario where it fails is when it is in the main scene in offline mode, we click a button to trigger reloading the scene in online mode which:

1. Sets our own offlineMode bool to false.
2. Calls PhotonNetwork.LeaveRoom().
3. Loads the transition scene.
4. In the Start method of a script in the transition scene, our ConnectToPhoton method is called.

The ConnectToPhoton method is as follows:

public void ConnectToPhoton() {
      if (offlineMode) {
                if (PhotonNetwork.connected) {
                    PhotonNetwork.Disconnect();
                }
                else {
                    OnDisconnectedFromPhoton();
                }
              return;
     }
    else {
         PhotonNetwork.offlineMode = false;
    }
     
     // If we are not connected to Photon, connect
     if (!PhotonNetwork.connected) {
            PhotonNetwork.ConnectUsingSettings(GAME_VERSION);
     }
     // Join the lobby if we haven't
     else if (!PhotonNetwork.insideLobby) {
            PhotonNetwork.JoinLobby();
      }
     // Join a random room
     else {
           PhotonNetwork.JoinRandomRoom();
      }
Joining the offline room shows the following logs:
- OnStatusChanged: Disconnect current State: Disconnecting
- OnConnectedToMaster() was called by PUN. This client is now connected.
- OnStatusChanged: Connect current State: ConnectingToGameserver
- Joined a room: offline room // This is our own log which logs the room name when a room is joined

When the room is left in order to switch to an online room, only the method for the OnLeftRoom callback provides logs:
public override void OnLeftRoom() {
            base.OnLeftRoom();
            Debug.Log("OnLeftRoom() was called by PUN.");
        }
I am expecting either of the following methods to receive callbacks after the room is left:

        public override void OnConnectedToMaster() {
            base.OnConnectedToMaster();
            Debug.Log("OnConnectedToMaster() was called by PUN. This client is now connected.");
            PhotonNetwork.JoinRandomRoom();
        }

        public override void OnJoinedLobby() {
            Debug.Log("OnJoinedLobby was called by PUN. This client is now connected.");
            PhotonNetwork.JoinRandomRoom();
        }
The client state of Photon at this point is 'ConnectedToGameserver', which according to the documentation means "Still in process to join/create room.(will-change)". Leaving it to process for a few minutes still does not trigger connecting to the master or joining the lobby.

I am not sure why Photon is not connecting to the Master Server after leaving the room, and appears to be still on the Game server. Any suggestions as to why it isn't, or what I might be doing wrong are appreciated.

In case it's useful, the Start method for our persistent (DoNotDestroyOnLoad) Network Manager script is:
void Start() {
            PhotonNetwork.autoJoinLobby = true;
            PhotonNetwork.automaticallySyncScene = false;
            PhotonNetwork.logLevel = logLevel; // Currently set to PhotonLogLevel.Full, and set to ALL in the inspector
            offlineMode = loadSceneOffline;
 }
I can provide more code blocks and logs if needed.
Sign In or Register to comment.