Search Unity

Loading AssetBundles and Resources

Discussion in 'Asset Bundles' started by BobbyBoy222, Sep 26, 2018.

  1. BobbyBoy222

    BobbyBoy222

    Joined:
    May 29, 2017
    Posts:
    3
    I think I've gotten the general idea of asset bundles and how to use them, I want to know if it's necessary to load an asset bundle (with AssetBundle.LoadFromFile()) more than once.

    With my set up right now (I've just started learning about asset bundles today), I'd be calling AssetBundle.LoadFromFile() for each object, but this seems wasteful? If several objects that require different assets in the bundle need to call it at around the same time, should I just have some sort of controller object load the bundle, then have each object load their respective asset?

    Right now I'm at a stage where I doubt this will impact any performance, but I'd like to know for future use. Also, I know the Unity docs recommends not using the Resources folder, but I wanted to see how far people have gone with it. I think I'm going to stick to Resources.Load for my smaller projects, but would like to hear about other's experiences with it.
     
  2. BobbyBoy222

    BobbyBoy222

    Joined:
    May 29, 2017
    Posts:
    3
    Just answered my own question about loading an asset bundle multiple times, I should have experimented more first. But the rest still stands: Best practices for loading bundles and/or from the resource folder?
     
  3. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    First of all, if you aren't downloading bundles from the internet, it's a good idea to rethink if you actually need them. If you are going to download them, then loading them from StreamingAssets can be a good option for development purposes.
    AssetBundle.LoadFromFile() is best for loading local files, except that "Async" version of it could be even better, but requires to write your code differently.
    Resources are not recommended. Try larger bundles and measure performance, likely StreamingAssets will be significantly faster on Android. Perhaps using LZ4 compression will make the difference smaller.