Unload(bool)
Unloads an AssetBundle freeing its data.
Read time 1 minuteLast updated 5 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.AssetBundleModule
public void Unload(bool unloadAllLoadedObjects)
Parameters
Determines whether the current instances of objects loaded from the AssetBundle will also be unloaded.
Remarks
When is false, tracking data structures and any memory buffers holding content of the AssetBundle are freed, but any instances of objects loaded from the bundle remain intact.
unloadAllLoadedObjectsWhen is true, all objects that were loaded from the bundle are destroyed. If any GameObjects in a Scene reference the destroyed assets, these references become missing.
unloadAllLoadedObjectsIn either case no more objects can be loaded from from the bundle unless it is reloaded.
For example, if a Material is loaded from AssetBundle :
MAB-
destroys all instances of
AB.Unload(true)referenced in the active scene.M -
keeps
AB.Unload(false)instances in memory but detaches them fromM, causing duplicates ifABis reloaded.AB
Warning: Unloading an AssetBundle that serves as a dependency for other asset bundles still in use can lead to undefined behavior. This includes serialization errors that may occur even if the dependency AssetBundle is later reloaded. To avoid such issues, ensure that an AssetBundle and all AssetBundles that depend on it are unloaded together.
For more information on the different compression formats used and their impact on memory while loaded, refer to AssetBundle compression formats .
Additional Resources: AssetBundle.UnloadAllAssetBundles, AssetBundle.UnloadAsync, Using AssetBundles Natively