Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved How to switch addressable scenes correctly?

Discussion in 'Addressables' started by RaventurnPatrick, Feb 5, 2021.

  1. RaventurnPatrick

    RaventurnPatrick

    Joined:
    Aug 9, 2011
    Posts:
    167
    Let's say we want to switch from our game scene to the main menu scene (both addressable)
    Now if calling Addressables.UnloadSceneAsync (assuming we have some more other scenes open), there is some strange artifacting - i.e. textures becoming black etc.
    However if we just call Addressables.LoadSceneAsync with LoadSceneMode.Single the AsyncOperationHandle of the game scene gets never unloaded (or that is our assumption)?

    So what is the correct way to switch from one scene to another without unloading assets that are still being displayed?
     
  2. unity_OSeBXw9aivkTJg

    unity_OSeBXw9aivkTJg

    Joined:
    Jul 8, 2019
    Posts:
    19
    I think you don't need to call UnloadSceneAsync when launching a new scene in LoadSceneMode.Single - I have tested this in profiler and looks like the memory is properly released, but not 100% sure, someone should confirm.
     
  3. Peter5897

    Peter5897

    Joined:
    Jan 4, 2017
    Posts:
    24
    At least for the version we're using, this is what the documentation says:

    https://docs.unity3d.com/Packages/com.unity.addressables@1.16/manual/MemoryManagement.html
     
  4. RaventurnPatrick

    RaventurnPatrick

    Joined:
    Aug 9, 2011
    Posts:
    167
    So i did some further experimentation and even when only using Addressables.LoadSceneAsync with LoadSceneMode.Single, there is strange artifacting going on (i.e. textures going black, materials going pink etc). Also certain scripts will fail because they depend on addressable assets in the update function (for example materials) - those are being pulled away while the scripts keep running.

    So the question still remains, how can we switch between 2 scenes without artifacts / causing script exceptions due to adressables being disposed?
     
  5. Peter5897

    Peter5897

    Joined:
    Jan 4, 2017
    Posts:
    24
    Do you have an example project with this behavior? I'm curious what the script exceptions would look like. My team has been using LoadSceneAsync() fine so far with LoadSceneMode.Single. We utilize a loading screen to hide the transition between scenes.
     
  6. RaventurnPatrick

    RaventurnPatrick

    Joined:
    Aug 9, 2011
    Posts:
    167
    I was able to track the problem down and it was not the fault of Addressables.LoadSceneAsync
    Instead we were calling:

    Code (CSharp):
    1. Addressables.Release(sceneLoadHandle);
    But releasing the scene load handles causes the strange behaviour. Instead not releasing the load handles and only using LoadSceneAsync does the trick (no strange artifacts / addressables being disposed)