Search Unity

AssetBundles and memory, optimal use for loading objects from a bundle?

Discussion in 'Scripting' started by Crayz, Jul 8, 2015.

  1. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    194
    My asset bundles contain a variety of objects including text assets containing scripts or bytes, scenes, and prefabs for different types of units and whatnot. When I load call AssetBundle.CreateFromFile() how are individual assets handled as far as memory goes? Whenever I need to retrieve a prefab from the bundle should I be calling bundle.LoadAsset() or would it be better to cache all the objects I need and retrieve them from the cache instead?

    Because my bundles contain scripts and byte data that must be executed or deserialized I'm iterating through all objects of the assetbundle using bundle.GetAllAssetNames, if the name contains a .txt extension and script_ prefix I'll retrieve the TextAsset and execute it in its proper place, if it contains .byte extension I'll deserialize and place it accordingly as well. If the name contains a .prefab extension I cache it into a dictionary, whenever I need to instantiate the prefab I'll retrieve it from the dictionary by key value. Is this optimal?