- Home /
Photon: I call PhotonNetwork.LeaveRoom() but my character doesn't leave
edit: this could be an issue in another script I'm using
I'm using PUN (free version).
After LeaveRoom()
is called, all the players and player owned objects get destroyed as expected, but
OnLeftRoom()
callback never gets called, and as a result, the player is stuck in the scene.
The script does something like this (and the class inherits from Photon.PunBehaviour
):
public void leaveRoom() {
PhotonNetwork.LeaveRoom();
}
public void OnLeftRoom() {
print("loading level");
PhotonNetwork.LoadLevel("MainMenu");
}
The bug only occurs when there's two players in the room.
update: it seems we attempt to connect to master after d/c but it never succeeds and photon does not throw any errors
This was the output from the NetworkingPeer.DebugReturn(...)
member method.
Resending: CMD(5 c#:255 r/u: 67/0 st/r#/rt:68313/1/78313). times out after: 56 sent: 68313 now: 68375 rtt/var: 24/8 last recv: 16
UnityEngine.Debug:Log(Object)
NetworkingPeer:DebugReturn(DebugLevel, String) (at Assets/StoreAssets/Photon/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1530)
ExitGames.Client.Photon.EnetPeer:SendOutgoingCommands()
ExitGames.Client.Photon.PhotonPeer:SendOutgoingCommands()
PhotonHandler:Update() (at Assets/StoreAssets/Photon/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:177)
Hi,
connecting to the $$anonymous$$aster Server is correct when leaving the room, but OnLeftRoom should be called nevertheless. If you have enabled PhotonNetwork.autoJoinLobby, please check if OnJoinedLobby gets called and if you try to connect to a room in this callback. The logging from the screenshot tells you, that the client has joined a game (room) twice in a row, which is strange - this is EventCode 226.
Which PUN and which Unity version do you currently use?
Answer by jahames · Oct 02, 2017 at 01:36 AM
I found a work around that "solves" this. Instead of leaving the room then waiting for the OnLeftRoom callback, I call PhotonNetwork.Disconnect()
then load level on the following line. This sometimes causes the player to load from in game -> main menu -> in game.
To fix this, I created a DontDestroyOnLoad
object which will make the player load the appropriate scene and knows when the player should be in the main menu.