Loading and unloading objects in a resource bundle (Assetbundle)
After you use the downloaded Data Build resource bundle (Assetbundle) object, you can load the objects contained in it in three different ways:
- Assetbundle.load uses its name identifier as the parameter-loading object. Its name is the name that appears in Project view. You can choose to pass the object type as a parameter to the load class function to ensure that a specific type of object is loaded.
- Assetbundle.loadasync works the same way as the above load class function, but does not block the main thread after the resource is loaded. This method is useful for loading large resources, or loading multiple resources at once, to prevent applications from stopping running.
- Assetbundle.loadall will load all objects in the resource bundle (Assetbundle). Like Assetbundle.load, objects can be selectively filtered according to their type.
To unload a resource, you need to use Assetbundle.unload. This class function contains a Boolean parameter that tells Unity whether to unload all data (including loaded resource objects) or only the compressed data in the downloaded resource bundle. If your application is using some of the objects in this resource bundle (Assetbundle) and you need to free some memory, you can pass false to unload the compressed data in memory. If you want to completely unload all objects of the resource bundle (Assetbundle), you should pass true to destroy the resources loaded from the resource bundle (Assets).
Asynchronously loading an object from a resource bundle (Assetbundles)
You can use the Assetbundle.loadasync class function to load objects asynchronously, reducing the likelihood of an application being temporarily interrupted.
How unity loads resources from Assetbundles