SubAssetAwareSO

SubAssetAwareSO is an example of a ScriptableObject that is "aware" of its sub-assets, in that it uses a List to keep references to them so that their reference can be always retrieved at runtime.

In this sample, the list is displayed in the asset's Inspector using a custom editor, so the user is informed of which sub-assets are present even when the main asset is not expanded in the Project window.

The MainObjective SO contains 3 sub-assets, which are visualised at the end of its Inspector

The sub-assets can be reordered in the list, though this is purely for tidying up in case they were added in an odd order, as it doesn't modify any functionality.

At runtime, the methods of SubAssetAwareSO can be used to access its sub-assets by name, or by class.

You can use this class as a starting point, and implement your own powerful "sub-asset aware" ScriptableObjects.


GetSubAssetByName

public virtual Object GetSubAssetByName(string subAssetName);

Returns the first sub-asset that has the specified name (Null if no sub-asset with this name is present).

GetAllSubAssetsByName

public virtual List<Object> GetAllSubAssetsByName(string subAssetName);

Returns all sub-assets that have the specified name (or an empty List if no sub-assets were found).

GetSubAssetByType

public virtual Object GetSubAssetByType<T>();

Returns the first sub-asset of the specified type (Null if no sub-asset of that type is present).

GetAllSubAssetsByType

public virtual List<Object> GetAllSubAssetsByType<T>();

Returns all sub-assets of the specified type (or an empty List if no sub-assets were found).

Last updated