Load Asset Bundle in unity3d – unity 5.x

In this article, I will explain how to load asset bundle in unity3d project. You can refer my article Create Asset Bundle in unity3d to know about creating asset bundles.

Load asset bundle in unity3d

You can load asset bundle either locally or from an URL. First download the asset bundle using WWW class then you can load objects from the bundle.

You can download asset bundle using WWW class.

  • Non-caching: Use object of WWW class to download data and it will be not cached in local storage of the device.

  • Caching: WWW.LoadFromCacheOrDownload method allows you to load asset bundle either from cache memory or by downloading it. If cache will be clean then it will download asset bundle otherwise it will load asset bundle from cache memory.
    The asset bundles are cached to the unity’s cache folder in local storage device. Size of caching is different for different platforms (web player, android, mac); unity web player allows to cache 50 MB of data.

You can also load asset bundle from file using AssetBundle.LoadFromFile(“Your path”) method. Usually you can store asset in applications streaming asset folder and can load from there.

Load Game object from asset bundle

First create an object of AssetBundle class from the downloaded data and then you can load objects from that asset bundle. You can use below mentioned methods of AssetBundle class to load objects from your asset bundles.

  • LoadAsset: This method will load object by their name, pass the name of the object that you want to load.
  • LoadAssetAsync: Same as above method, but loads object asynchronously; so doesn’t blocks application’s main thread.
  • LoadAllAssets: This method will load all the objects in your assets bundle.

Once you load the game object from asset bundle, instantiate it to use in the scene.

Load scene from asset bundle

First load all the assets from associated scene asset bundle then load scene using SceneManager.LoadScene method.

Unload Asset bundle

Once you load the objects from asset bundle then unload asset bundle using AssetBundle.Unload method. This helps to conserve the memory and improves performance.

That’s it for the article – load asset bundle in unity3d. Hope you enjoyed it. Post your comments for queries and feedback. Thanks!

Share Button
The following two tabs change content below.
Gyanendu Shekhar is a technology enthusiast. He loves to learn new technologies. His area of interest includes Microsoft technologies, Augmented reality, Virtual reality, unity3d and android development.

Gyanendu Shekhar

Gyanendu Shekhar is a technology enthusiast. He loves to learn new technologies. His area of interest includes Microsoft technologies, Augmented reality, Virtual reality, unity3d and android development.

One thought on “Load Asset Bundle in unity3d – unity 5.x

  • November 6, 2016 at 9:52 pm
    Permalink

    Awesome blog, going to bookmark it!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *