Search Unity

AssetBundle.Unload() destroys AssetBundle reference. Bug?

Discussion in 'Asset Bundles' started by snw, Sep 17, 2018.

  1. snw

    snw

    Joined:
    Mar 13, 2014
    Posts:
    31
    Hi,

    just encountered a thing - still unsure if its a bug or feature.
    I'm using Unity 2018.2.8f1.

    Scenario:
    1. Load an AssetBundle from server and save reference in variable assetBundle.
    2. After assetBundle downloaded successfully, load assets from assetBundle.
    3. After assets loaded successfully from assetBundle, instantiate assets.
    4. After instantiation of assets, call assetBundle.Unload(true) or assetBundle.Unload(false).

    Result:

    assetBundle gets destroyed, i.e. gets set to null.

    Expected Result:
    The documentation (link) only mentions that the assets of an AssetBundle get destroyed, not the AssetBundle itself. I would therefore expect assetBundle to be still intact after having called assetBundle.Unload().

    The downside of the current behaviour is that you have to redownload an AssetBundle everytime after AssetBundle.Unload() has been called.

    So, is this how it's meant to be?


    Cheers.
     
    Last edited: Sep 17, 2018
  2. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    223
    Why are you using the Unload() API when you are still using the asset bundle and data used from the asset bundle?
    Proper Unload() API usage should be to call it with "true" when you are done using the bundle and it's data and want to Unload all the data from memory. Calling it with "false" is more of an advanced use case that I would never recommend for everyday use.

    Also have you looked at using Addressables package at all? It will manage all of the asset bundle api complexity for you. https://forum.unity.com/forums/addressables.156/
     
  3. snw

    snw

    Joined:
    Mar 13, 2014
    Posts:
    31
    Thanks for your feedback.

    Because in my understanding, Unload() does only affect assets within an AssetBundle, not the AssetBundle itself. At least that is what the documetation implies. Nowhere is stated that the AssetBundle gets "nullified", only that AssetBundle contents (compressed or instanced) will get cleared. Maybe an update to the documentation could avoid this misunderstanding.

    Nope, but thanks for the hint. As the framework is still in beta, I guess it's a bit too early to use it in a commercial project.
     
    Last edited: Sep 18, 2018
  4. unity6d

    unity6d

    Joined:
    Jan 31, 2018
    Posts:
    2
    i am facing same issues, multiple asset-bundle loading app going to crash (android & iOS).
     
  5. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    223
    Will look into improving the docs for that API.