How to return from game to room

Options
My app allows the master to create a room and automatically joins it and it displays the players names who have joined.
When a client opens the app they see the available rooms, in this case just the one, and allows them to join.
Now both master and client see the list of players in the room.
The master then starts the game which calls PhotonNetwork.LoadLevel(2) and everyone loads...level 2.

I now want a "Leave Room" button to let players leave the room which I have added and it calls PhotonNetwork.LeaveRoom().

This however leaves the player in the level 2 scene but in the console I see this out put:

OperationResponse 254: ReturnCode: 0.
OnStatusChanged: Disconnect current State: DisconnectingFromGameserver
OnStatusChanged: Connect current State: ConnectingToMasterserver
Connected to masterserver.
OnStatusChanged: EncryptionEstablished current State: Authenticating
OnEvent: Event 226.
OperationResponse 230: ReturnCode: 0.
OnEvent: Event 226.
PUNVoice: Resending: CMD(5 c#:255 r/u: 25/0 st/r#/rt:26748/1/36748). times out after: 94 sent: 26748 now: 26848 rtt/var: 50/11 last recv: 1

Not sure why PUNVoice is there as although in the project, it is not yet implemented?

I then tried this:

PhotonNetwork.LeaveRoom();
PhotonNetwork.LoadLevel(1);

which does put the player that tapped the button back to level 1 but I get this in the console:

PUN-instantiated 'Main Camera' got destroyed by engine. This is OK when loading levels. Otherwise use: PhotonNetwork.Destroy()
PUN-instantiated 'MyContainer' got destroyed by engine. This is OK when loading levels. Otherwise use: PhotonNetwork.Destroy()
PhotonView ID duplicate found: 999. New: View (0)999 on PlayerNetwork (scene) old: View (0)999 on PlayerNetwork (scene). Maybe one wasn't destroyed on scene load?! Check for 'DontDestroyOnLoad'. Destroying old entry, adding new.
UnityEngine.Debug:LogError(Object)
NetworkingPeer:RegisterPhotonView(PhotonView) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3502)
PhotonView:Awake() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:269)
Network destroy Instantiated GO: PlayerNetwork
UnityEngine.Debug:Log(Object)
NetworkingPeer:RemoveInstantiatedGO(GameObject, Boolean) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3362)
NetworkingPeer:RegisterPhotonView(PhotonView) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3509)
PhotonView:Awake() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:269)
Registered PhotonView: 999
UnityEngine.Debug:Log(Object)
NetworkingPeer:RegisterPhotonView(PhotonView) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3518)
PhotonView:Awake() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:269)
Connecting to server..
ConnectUsingSettings() failed. Can only connect while in state 'Disconnected'. Current state: Connected
OnStatusChanged: Disconnect current State: DisconnectingFromGameserver
OnStatusChanged: Connect current State: ConnectingToMasterserver
Connected to masterserver.
OnStatusChanged: EncryptionEstablished current State: Authenticating
OperationResponse 229: ReturnCode: 0.
OnJoinedLobby() called: Joined lobby with user name: Joe Bloggs

So basically...I'm stumped as I dont get whats going on :neutral:

Comments

  • Hi @piginhat,

    when you call PhotonNetwork.LeaveRoom(); the client basically waits for a server response. In your case you don't wait for that response, furthermore you directly load another scene. After this scene has been loaded you receive the previously mentioned response. When the client processes this response - or this response has been processed - the callback OnLeftRoom() is called.

    So what you have to change to leave the room without any warnings (or errors) is to only call PhotonNetwork.LeaveRoom(); firstly and wait for the OnLeftRoom() callback which you have to implement obviously. In this callback you can load another scene without using PhotonNetwork.LoadLevel, because you are not in a room any longer - you can just use the 'normal' LoadScene function.