Photon Engine (PUN 2) trouble returning to lobby

Hello all,

I have started working with PUN 2 recently and I am having trouble finishing the gameplay loop.

So far I can get the client connected to the photon network, create a room and have other players join it, and start the game with other players.

The problem starts when I am trying to create a new room after leaving the game.
When calling JoinOrCreateRoom I get this error

JoinOrCreateRoom failed. Client is on GameServer (must be Master Server for matchmaking)but not ready for operations (State: Leaving). Wait for callback: OnJoinedLobby or OnConnectedToMaster.
UnityEngine.Debug:LogError(Object)

Here is a screenshot of my disconnect code

When I run the OnQuitMultiplayer function, the client begins to disconnect from the room, but never actually disconnects. because of this I can’t create or join any other rooms without resetting the game.

I’m not really sure what I am missing, any and all help is greatly appreciated

Behind the scenes, there is a Master Server for matchmaking and Game Servers for the gameplay. So you have to leave the room (which also leaves the Game Server and returns the client to the Master Server) before you can JoinOrCreateRoom()…

Hello and sorry for the late response,

I actually am calling LeaveRoom before I try to create another room (see screenshot in original post), but for some reason, the client state gets stuck in the “Leaving” state and never actually calls OnLeftRoom or reconnects to the Master. I’m not too sure what’s going wrong.

Leaving a room will also switch servers, so it’s taking a moment. Wait for the callback which tells you PUN is back on the Master Server, then do the matchmaking. Errors in the logs typically point out the names of the methods to wait for.

If you are not using the latest PUN 2, update. There was one fix for this a while ago.

Are there other methods to wait for besides OnLeftRoom or OnDisconnected? I have tried LeaveRoom and Disconnect and for some reason they both keep the client state in “Leaving” and the callbacks never execute during gameplay, only when I stop running it in the editor.

I am using PUN 2 2.15 from the asset store and I didn’t see a more up to date version.

Wait for callback: OnConnectedToMaster.

Oh I had the same Problem.
It turned out, my problem was , that whily try leaving the timescale was 0. By setting time. Time.timeScale = 1 is worked ;D

2 Likes

Hello dude, try adding this script: Time.timeScale = 1;
above the script: PhotonNetwork.LeaveRoom();

if any one wanna return to the lobby in his game
this code for you

public void LeaveRoom() // define function and join it with button
{
PhotonNetwork.LeaveRoom();
PhotonNetwork.AutomaticallySyncScene = false;
PhotonNetwork.LoadLevel(0);
}

Thank You so much asshole,u saved my day!!