Lazy Asset Lists

Pro Only: Weaver Lite allows you to try out asset lists in the Unity Editor, but they will always be empty in a runtime build unless you purchase Weaver Pro.

A regular Asset List that derives from AssetList<T> simply serializes a list of direct references to its assets, meaning that they will all be loaded into memory immediately when the list is loaded. This is often undesirable, particularly when referencing large assets or lots of them at once. Instead, you can enable the Is Lazy toggle when generating the list type to have it inherit from LazyAssetList<T> so that it will serialize the resource paths of its assets and only load them as they are needed at runtime. Note that this means the target Directory must be in a Resources folder.

Once you have a LazyAssetList<T> you can access the asset or path at any given index using GetAsset or GetPath respectively. You can also use MapPathToIndex to compile a Dictionary<string path, int index> that will let you look up the index of an asset using its path. This can be useful for example if you want to select an asset from the list and serialize its path, then deserialize it and continue accessing that asset through the list.

Meta Asset Lists

It can also be useful to have access to certain data about the listed objects without needing to load the whole object. The Item Shop example has an Item class with an ItemMetaData field containing details about each item such as the name, cost, and icon. This allows it to use an ItemList (which inherits from MetaAssetList<Item, ItemMetaData>) to serialize the meta data alongside the resource path of each item. Then at runtime the ItemDisplay class is able to display those details without loading the actual items. Note that in the Unity Editor the list will always load the assets immediately to ensure its stored meta data is up to date, but in a runtime build it will only load them on demand.

The above example has Item implement the IMetaDataProvider<ItemMetaData> interface for each Item to explicitly specify its meta-data, but any type with a constructor taking a single Item parameter could also be used as the meta-data type.