Search Unity

How to unload the bundle from which scene was loaded

Discussion in 'Addressables' started by Darkwing_Duck, Nov 25, 2018.

  1. Darkwing_Duck

    Darkwing_Duck

    Joined:
    Sep 29, 2016
    Posts:
    11
    Hi all, so, I trying to move heavy scene and related to it assets to an addressable group - it will be an asset bundle as I know.
    It looks like this:


    Then I can load the scene, like this:
    Code (CSharp):
    1. Addressables.LoadScene("HeavyScene");
    And in addressables profiler I see :
    \
    So, my asset bundle "remote_scenes_heavyscene" was loaded and my "HeavyScene" now on my screen and I have one reference count to it. Ok.

    But the question is How can I unload the asset bundle? Because when I load another scene the profiler still show me one reference and when I try to load the "HeavyScene" again, profiler shows to me 2 references to the asset bundle.

    How to correct completely unload the asset bundle?
     
    Last edited: Nov 25, 2018
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    You should just be able to call Addressables.UnloadScene(), which will decrement the ref count on the scene, and thus the bundle as well. If that's not working, let me know.
     
  3. Darkwing_Duck

    Darkwing_Duck

    Joined:
    Sep 29, 2016
    Posts:
    11
    Hi, thanks for the answer.
    Yes, it what I did at first, but got an error like - "You can't unload the last loaded scene".
    And it works fine if I loaded scene as Additive but not as single.
    So, i load scene as single the reference count to the scene is remains
     
    Last edited: Nov 30, 2018
  4. jsmouret

    jsmouret

    Joined:
    Apr 4, 2015
    Posts:
    8
    It looks like to it is not working... at least when loading the scene in Additive mode.
    I had to save the dependencies returned by Addressables.PreloadDependencies and then call Addressables.ReleaseAsset on each of them after unloading the scene.
    It shows quite nicely in Virtual Mode with the Addressables Profiler.
     
  5. niX_BB

    niX_BB

    Joined:
    Mar 29, 2010
    Posts:
    26
    I may be running into the same issue when loading scenes Additively. (Also using Virtual Mode)

    Addressables.UnloadScene does unload the scene but does not seem to reduce the refcount in the profiler.
     
  6. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Thanks for all the info, we'll spend some time digging into this.