Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Associating GetAllAssetNames() with LoadAllAssets()

Discussion in 'Asset Bundles' started by pb_martinwickham, Jan 29, 2019.

  1. pb_martinwickham

    pb_martinwickham

    Joined:
    Mar 9, 2017
    Posts:
    3
    Hi all,
    I'm setting up an asset system based on the following idea:
    1) users of the system request bundles they may need for a period of time
    2) those bundles (and their dependencies) are loaded asynchonously
    3) all assets in the bundles are preloaded via LoadAllAssetsAsync
    4) users fetch the preloaded assets synchronously by type and filename (something like LoadAsset but it just does a fast lookup to one of the existing objects that was previously returned by LoadAllAssetsAsync)
    5) When the user is done, they release their requested bundles, and if no other scopes are using them the bundles are disposed.

    Unfortunately, in order for this to work, I need a way to associate the objects in the array returned by AssetBundle#LoadAllAssetsAsync() with the paths returned by AssetBundle#GetAllAssetNames(). Trying to use the same index won't work, since some assets (like .png files) generate multiple assets (a Sprite and Texture asset), so the array of assets can be longer than the array of paths.

    I've been searching through documentation and blog posts but can't find any good way to do this. If possible, I'd like to avoid creating my own manifest file to pack into each asset bundle, since it's clear that this information is already in the bundle somewhere (just maybe not accessible).

    Any recommendations?
     
  2. pb_martinwickham

    pb_martinwickham

    Joined:
    Mar 9, 2017
    Posts:
    3
    Some experimentation shows that Unity keeps an internal cache of loaded assets, so calling LoadAsset(..) several times will be fast once the asset is loaded and calling LoadAllAssets() will prime the cache. This removes most of the need for a solution to this question.
    LoadAsset hitting the cache still seems to be ~4x slower than an equivalent dictionary lookup, but it's fast enough for my current purposes.

    If anyone finds this and still needs a solution, it seems like it would be doable by using the SerializedObject API and iterating the
    m_Container
    property, similar to this example: https://support.unity3d.com/hc/en-u...Which-Assets-are-included-in-an-Asset-bundle-

    Edit: SerializedObject is only available in the editor so this does not actually solve the problem. Maybe baking a custom manifest is the only way to go?