I’m trying to use Application.LoadLevel() to get back to a lobby scene in a project, from the game scene. It is called in OnLeftRoom and is the only thing that happens there.
Unless I destroy every GO in the scene directly after calling LoadLevel (as shown below) Unity crashes. If I do destroy every GO, Photon gets stuck in the “Disconnecting” connection state.
function OnLeftRoom () {
Application.LoadLevel(1);
// Get rid of the entire scene
for (var obj : GameObject in FindObjectsOfType(GameObject))
Destroy(obj);
}
I am using LoadLevel all over the place elsewhere in the project without problems. (For instance, going from the lobby scene to the game scene).
Any ideas why LoadLevel is failing so badly? I suspect it has something to do with Photon but that’s based on the fact the same idea worked pre-Photon (by disconnecting, loading the level and connecting to the lobby’s master server, rather than the room system Photon uses).
Apologies if I put this in the wrong section. I’m not sure if it belongs in Scripting or here.
Interesting issue. I will have to find some time to check this.
Maybe it is a conflict between some other clean up code and the one triggered by Application.LoadLevel().
Do you use PhotonNetwork.LoadLevel elsewhere?
It also might be related to PUN potentially running coroutines on an GameObject that’s not destroyed on load, instead of running them on the respective GameObject. This is something we recently changed (fixed) but didn’t release yet. It seems less likely, because you can destroy the GO’s just fine.
There’s a chance than PN’s load level is used elsewhere following the convertor tool’s work on the project, but I doubt it - I’ve checked most of the scripts in the project.
I don’t have anything that fires when the level changes. The lobby script does start with the following code… since the complete-destroy fixed the crash I highly doubt it’s this but having watched the connection state change during room leaving I worry that this might be the cause:
function Start () {
if (PhotonNetwork.connectionState != ConnectionState.Connected) {
PhotonNetwork.isMessageQueueRunning = true;
PhotonNetwork.ConnectUsingSettings("v1.0");
}
}
I am curious what causes this and isually I would say “send me a small repro case” and have a look. However, at the moment I’m pretty swamped and you seem to have a workaround.
If you want to, send the test project to developer@exitgames.com and I might return to it when it’s less busy. Thanks!