Search Unity

Question Is it possible to asynchronously unload one scene while loading another (plus some extra assets)?

Discussion in 'Addressables' started by JesseSTG, Sep 15, 2021.

  1. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    My game only has one built-in scene, and it's empty. This built-in scene is where global game managers (UI event systems, platform services, etc.) reside after being instantiated at launch. After that, all scenes and assets are loaded with Addressables.

    When I do transition between scenes, I want it to be as seamless as possible. I figure that's possible by doing a lot of work in the background. So I'd like to be able to do the following, in order:
    1. Decide that it's time to move to another scene.
    2. Additively load a new scene, but don't activate it yet. At the same time, load assets that don't exist in-scene but are still needed for it (e.g. prefabs that will be spawned at runtime).
    3. When the new scene is ready to activate, unload the currently-active scene (unless it's the aforementioned bootstrap scene).
    4. When the currently-active scene is unloaded, activate the newly-loaded scene.
    However, the docs for AsyncOperation.allowSceneActivation suggest that taking the above steps would cause a deadlock (but correct me if I'm wrong).

    Given this information about my use case, how can I load a scene (and some extra assets) in the background, unload the current scene, then activate the new one when it's ready?