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

ASync level loading problems.

Discussion in 'Scripting' started by KristoE, Feb 19, 2017.

  1. KristoE

    KristoE

    Joined:
    Oct 13, 2012
    Posts:
    90
    I am having problems loading a Scene ASync.
    What I want to achieve is to preload a new Scene, but not activate it yet.
    Then at some point I create a temporary empty scene and move some objects that need to be carried on to the new scene into that temp scene.
    After that I want to unload the old scene and only after the old scene is unloaded I want to activate the new scene.
    But it seems that the unload operation can't finish before the new scene, that was loaded before, has been activated.

    Am I doing something wrong here?
    What would be the correct way to approach this problem?
     
  2. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    If you use the additive async loading then you can use it to simply add gameobjects into the hierarchy. When you're ready to change scenes you enable these gameobjects and delete the other gameobjects.
     
  3. KristoE

    KristoE

    Joined:
    Oct 13, 2012
    Posts:
    90
    Thanks for the reply,
    SceneManager.LoadSceneAsync(levelToLoad,LoadSceneMode.Additive);
    Is this what you mean?
    This is what I am currently using, but it seems that it will automatically activate all the objects once they are loaded if I don't use allowSceneActivation = false;
    And that will create the problem that I can't unload a scene before this scene has finished loading(that includes activation)
    I guess I could create a parent object in every scene that will be inactive by default, but in that way I would have to refactor some code, as I use transform.root in some of it.

    Currently it just seems that SceneManager functionality is just poorly made, as I see no reason why it would require me to activate the loaded scene before I can unload some other scene.
     
  4. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Yes, that's what I meant. I didn't know about the scene activation thing.

    I loaded scenes this way in an old game before the new SceneManager. I unloaded scenes by deleting the root object.
     
  5. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    I'm having the same issue, trying to load the next scene additively and set it's activation to false, fade out to black, unload the current scene and when it's unloaded set the next scene's activation to true and it just doesn't work, if i set to allow the activation to true before unloading the current scene the next scene loads on top of the current scene and it creates a huge mess for the duration of the 2-3 frames that it takes for the UnloadSceneAsync to finish.

    I've spend the past days trying to get UnloadSceneAsync to work and it's a total nightmare, loosing so much time, unable to find any help, like you said it's just poorly made, i think I have no other options than to stick with UnloadScene which worked perfectly and never upgrade to unity 5.6+.