PUN 2 Client state stuck in "Leaving" after leaving game, Cannot create a new room

Options
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
https://imgur.com/a/C5HjnOt

When I have the network state check in the coroutine, the while loop loops forever and does not execute the LoadScene code. However, when I remove that check, it Loads the "Rooms" scene, but the state is still in "Leaving" and I cannot create a new room.

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

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @OokumSpookum,

    Thank you for choosing Photon and sorry for the delayed response, I got this one bookmarked as a reminder to answer but sometimes we miss some discussions.

    Anyway.
    First I think the code from the screenshot is a bit orthodox in PUN's world.
    I would not use coroutines for leaving rooms.
    PUN has useful callbacks.
    Load the scene inside IMatchmakingCallbacks.OnLeftRoom callback.
    Besides, I would not compare enum values to strings after converting it to string, you could easily compare to ClientState.Joined value directly for efficient and cleaner code.

    Change this and see if the issue remains.
  • Hi @JohnTube,

    I have switched the coroutine to the OnLeftRoom callback, but it is still not leaving the room. I have included a screenshot of the updated code: https://imgur.com/a/0M9qKzm
    I'm not really sure what I'm doing wrong here, but I could have easily missed some steps.

    Thank you for your time