Search Unity

AssetBundle.UnloadAllAssetBundles() doesn't unload scene bundles

Discussion in 'Asset Bundles' started by PW_Dave, Jan 17, 2019.

  1. PW_Dave

    PW_Dave

    Joined:
    Feb 9, 2017
    Posts:
    30
    I've been doing some testing of the AssetBundle system in order to formulate a plan to support variants with our asset management system. I have a custom editor that exposes most of the raw functionality of the AssetBundle system and I've discovered that AssetBundle.UnloadAllAssetBundles() does not unload scene bundles. Which is kind of annoying.

    My custom editor works fine when I use it to load/unload bundles and I can keep track of everything. But when I open the window during a play session or after closing/recompiling, any scene bundles that are loaded are effectively inaccessible. Due to the following issue (where AssetBundle.GetAllLoadedAssetBundles() doesn't return scene bundles): https://forum.unity.com/threads/ass...etbundles-not-returning-scene-bundles.503657/ , I can't get a reference to the loaded scene bundle. It's basically orphaned and stuck in memory. I have to restart Unity to fix it.

    I'm using Unity 2018.2, in case it's been fixed since then.
     
    unity_QzmvR2WrBsSXAw likes this.
  2. PW_Dave

    PW_Dave

    Joined:
    Feb 9, 2017
    Posts:
    30
    After further work, it turns out that I just need to enter/exit play mode to workaround this issue. Apparently, exiting play mode unloads all bundles including scene bundles. Still, it would be nice to have this fixed.
     
  3. Pardhi_Rohit

    Pardhi_Rohit

    Joined:
    Feb 15, 2018
    Posts:
    2
    Found any solution for this issue ? I am facing the same problem.
     
  4. PW_Dave

    PW_Dave

    Joined:
    Feb 9, 2017
    Posts:
    30
    We are still using the same version of Unity (2018.2.15f1) as we were when I made this post, so I don't know if it's been fixed. I ended up entering/exiting play mode whenever I needed to make sure everything was flushed. We are going to upgrade to 2018.4 next week, so perhaps it has been fixed by then? I think that you may be able to use a ScriptableObject to maintain a list of loaded bundles and it would persist beyond refreshes and compilations? I'm not sure about that though.
     
  5. mowax74

    mowax74

    Joined:
    Mar 3, 2015
    Posts:
    97
    It's still not fixed. Just run into the same issue. AssetBundles with prefabs in it were unloaded, but an AssetBundle with a scene in it was not. Has someone a workaround for this?
     
  6. PelvisParsley

    PelvisParsley

    Joined:
    Aug 9, 2016
    Posts:
    89
    Same issue in 2021.2.16f1
     
  7. spaceman8

    spaceman8

    Joined:
    Jan 6, 2017
    Posts:
    40
    Any updates on this - no progress since it was reported in 2019? I am having this issue as well using Unity 2020.3.33f1. After you unload everything with
    Code (CSharp):
    1. AssetBundle.UnloadAllAssetBundles(true);
    2. Resources.UnloadUnusedAssets();
    and then try to load a previously loaded bundle with a scene, I get the error:
    The AssetBundle 'xyz.bundle' can't be loaded because another AssetBundle with the same files is already loaded.
    I then tested to see what bundles are still loaded with
    AssetBundle.GetAllLoadedAssetBundles()
    but the list is empty. I also checked the SceneManager scene list and my previous scene is not there. Is there some place else to check if its loaded and unload it without using the AssetBundle.Unload... methods since it seems Unity does not care to fix this issue?

    Update: I should note I am doing this purely through Editor code, not Play mode.
     
  8. MorganYT

    MorganYT

    Joined:
    Jul 29, 2017
    Posts:
    31
    You can try this, it works but not exactly as I need it.
    Code (CSharp):
    1.  
    2.         foreach (AssetBundle asset in Resources.FindObjectsOfTypeAll(typeof(AssetBundle)) as AssetBundle[])
    3.         {
    4.             asset.Unload(false);
    5.         }
    6.  
    and you can follow the error: https://issuetracker.unity3d.com/is...n-unloadallassetbundles-true-method-is-called
     
    Last edited: Nov 20, 2022