Search Unity

Is this how to use asset bundle?

Discussion in 'Asset Bundles' started by lofwyre, Aug 3, 2017.

  1. lofwyre

    lofwyre

    Joined:
    Apr 19, 2007
    Posts:
    174
    Hi, I'm just starting with asset bundles, I've been reading docs and blogs. I kinda get it but would like some clarification.

    This is for PC.

    I want to use asset bundles to allow new content to be dynamically added to my game.

    So my steps would be
    • When game is starting up
    • Check for new updates, I'll work out a way to determine if there is an asset bundle I need to download
    • Use UnityWebRequest to download an assetbundle to a specified folder
    From this point regardless of new or not new my game needs to consider there are potentially asset bundles stored locally to use.
    • Directly after starting up
    • Examine what assetbundles I have and create a list of what I need to load (for the general use and the current scene)
    • Use AssetBundle.LoadFromFile for bring those objects into memory

    I'm considering having my own header type file with each assetbundle that tells me what assets belong to what scenes and should therefore be loaded for use.

    Is this an ok way to move forward or am I missing something fundamental?

    Cheers
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    You are missing the built in AssetBundle caching system.
    UnityWebRequest has a dedicated API for AssetBundles which only downloads the AssetBundle if it's not already cached. You need to check your server for versions/CRCs/Hashes of available asset bundles. As long as you keep the same URL for each AssetBundle when updating, then you simply need to pass version/CRC/Hash along with URL to UnityWebRequest and that bundle will only be downloaded if it is not cached yet, otherwise if will be loaded from cache.

    Read more about UnityWebRequest.GetAssetBundle(), as well as AssetBundle and Caching APIs.
     
  3. lofwyre

    lofwyre

    Joined:
    Apr 19, 2007
    Posts:
    174
    ok, thanks. So once downloaded then it's AssetBundle.LoadFromFile if I want to use a particular asset from the bundle in the current scene right? And to work out what is in the bundle do I keep my own list asset (like a csv) or can I read from the asset name from a manifest?

    Cheers
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    You should really read our API documentation.

    After you download AssetBundle via UnityWebRequest.GetAssetBundle(), you can get the bundle using DownloadHandlerAssetBundle.GetContent(), which will give you the bundle regardless of whether it was donwloaded or loaded from cache.

    AssetBundle class also has plenty of APIs to see what's inside a bundle.