Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Unity Crashing on LoadLevel - due to Photon?

Discussion in 'Multiplayer' started by Simba, Jan 4, 2014.

  1. Simba

    Simba

    Joined:
    Nov 8, 2010
    Posts:
    77
    Hi,

    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.
    Code (csharp):
    1. function OnLeftRoom () {
    2.     Application.LoadLevel(1);
    3.     // Get rid of the entire scene
    4.     for (var obj : GameObject in FindObjectsOfType(GameObject))
    5.         Destroy(obj);
    6. }
    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.
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    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.
     
  3. Simba

    Simba

    Joined:
    Nov 8, 2010
    Posts:
    77
    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:
    Code (csharp):
    1.  
    2. function Start () {
    3.     if (PhotonNetwork.connectionState != ConnectionState.Connected) {
    4.         PhotonNetwork.isMessageQueueRunning = true;
    5.         PhotonNetwork.ConnectUsingSettings("v1.0");
    6.     }
    7. }
    Thanks for the response :)
     
    Last edited: Jan 6, 2014
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    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!
     
  5. Simba

    Simba

    Joined:
    Nov 8, 2010
    Posts:
    77
    I do have a workaround, but it force-disconnects me every time I quit and then will not allow reconnecting...

    I'll rig up a simplified test project and send it there if I can't fix it, then. Thanks for your help :)