Give Page Feedback

World Designer Tool - Asset Managers

Asset Managers, as the name implies, control how Assets are managed in the Editor. Where the Chunk Streamer is responsible for loading and unloading Asset Chunks at runtime, the Asset Manager performs those same duties in the Editor.

In addition, Asset Managers control some other functionality that is Editor exclusive, such as detecting whether Assets exists, detecting whether they need to be saved, saving them, and deleting them. The only aspect they do not manage is the creation of new Asset Chunks, which is the responsibility of the Asset Creator.

Finding Asset Managers

In order to support the addition of custom Asset Types, and really to make the full asset management pipeline customizable, the World Designer Tool does not use a pre-set suite of Asset Managers. Instead, the Asset Managers are Scriptable Assets that can be placed in a special folder that the World Designer tool can pull from when the Managers are needed. This gives you the flexibility to create custom Asset Manager classes and then create assets from them which can be placed in the special folder. The full breakdown for how the World Designer Tool finds and retrieves the correct Asset Manager for an LOD is as follows:

1) Identify the Chunk Streamer associated with a particular LOD.

2) Use object.GetType to get the type of the Chunk Streamer, then generate the asset manager file name from the Type.Name property. The full file name is Type.Name_AssetManager.

3) Retrieve the Asset Manager asset with the name generated in step 2 from the Assets/Editor Default Resources/Deep Space Labs/SAM/AssetManagers folder.

When an Asset Manager does not exists with the correct name, the World Designer will automatically generate a default Asset Manager asset within this folder if the Chunk Streamer from step 1 is a PrefabChunkStreamer or SceneChunkStreamer. Chunk Streamers of other types will throw an exception when no Asset Manager is present for them!

Default Addressable Asset Managers

Like the PrefabChunkStreamer and SceneChunkStreamer, the Addressable Chunk Streamer classes have default Asset Managers included with the Streamable Assets Manager that you can make use of.

However, because these Asset Manager classes are dependent on the Addressables package being present in your project, they have been placed outside the normal Class Library. The result is that these Asset Managers cannot be automatically created like the other Asset Managers. They require a command to be executed by you!

These commands can be found in the Assets menu, under Assets - > Deep Space Labs -> SAM -> Regenerate Default Prefab Addressable Asset Manager and Assets - > Deep Space Labs -> SAM -> Regenerate Default Scene Addressable Asset Manager. The commands will generate the needed assets and place them inside the correct folder.

Using Custom Asset Managers

The Default Asset Managers will work perfectly in most cases, however if you ever wish to replace them with custom Asset Managers (including the Addressable Managers), all you need to do is remove the existing default assets from the folder specified in step 3 above, create a custom class deriving from AssetManager, implement all required members, create a physical Scriptable Asset representing the Asset Manager, place it inside the folder form step 3 above, and rename it to match the name described in Step 2. These steps are the same when you need to add an Asset Manager for a custom Chunk Streamer (minus the removal of the existing Asset Manager from the folder).

The Streamable Assets Manager does not by default include Asset Manager assets within the Project Hierarchy. This is necessary to avoid overwriting any custom assets you have created and added to the special folder when updating the package from the Package Manager.

The beauty in this design is that you can easily switch between a custom Asset Manager and one of the default Asset Managers with very little effort. All you need to do is change the name of the Asset Manager that you want used to the name described in step 2 above. If you have more than one Asset Manager that can be used with the same Chunk Streamer, just rename the Asset Manager you want to temporarily disable to a name that does not match the expected format.

Custom Asset Managers (Required Method Implementations)

If you wish to create a custom Asset Manager, start by deriving either directly from AssetManager or from one of the partially implemented Asset Manager classes (PrefabBasedAssetManager or SceneBasedAssetManager). The former gives you the greatest degree of control, however the latter is easier to work with (but gives you limited flexibility to control things).

While the API does not include any information about the methods you need to override, once you inherit from one of the classes described above, you will see an error messages on the Class Name telling you certain methods need to be implemented. Simply click this error message and choose Show potential fixes -> Implement abstract class. Once the methods that are required to be implemented are added, you can hover over the method and parameter names to see all the information you should ever need.

--Special Note--
Most of the methods have a return type of IEnumerator, however in reality the only yield statement you can use is yield return null. This can be used to tell the calling code to yield for a single editor frame, which is useful for stopping the editor from becoming unresponsive. You cannot yield other objects, such as WaitForSeconds!

Custom Asset Managers (Asset Chunks)

AssetChunk objects are used to store the Asset Chunks asset when using the World Designer tool. If you wish to support custom Asset Types, you can create a new custom class that derives from AssetChunk, and then create an Asset Manager that derives directly from the base AssetManager class. This will give you full control over the type of AssetChunk created, allowing you to use your own custom type.

Custom Asset Managers (Optional Method Implementations)

There are a few methods which can be optionally implemented, depending on which class you derive from.

If deriving from AssetManager, PrefabBasedAssetManager or SceneBasedAssetManager, these methods include:

1) CleanupAssetChunksWithMissingAssets: Occassionally AssetChunk objects are left behind with missing assets. In these cases, those AssetChunk objects may require additional cleanup, in which case you can override this method.

2) IsAssetChunkEmpty: When performing Evaluation Operations on Asset Chunks, the World Designer tool queries this method in order to determine if an Asset Chunk is empty. If not overridden, the method will return true only if the Asset Chunk has no child game objects and no components other than a Transform. You can override the method to provide alternative logic.

Custom Asset Managers (Generating the Asset)

Once you finish creating custom Asset Manager script, you will need to make an editor command to generate new instances of the Scriptable Asset within your project. To do so, create a static method inside some editor class that has the following attribute:

[MenuItem(GlobalValues.ASSET_CREATION_PATH + "Custom Asset Manager Name", false)]

Within this method, you can use the following line of code to create the Scriptable Asset, replacing CustomAssetManager with the class name of your Custom Asset Manager.

ScriptableObjectAssetCreator.GenerateScriptableObjectAssetAtSelectedFolder("CustomAssetManager");

ScriptableObjectAssetCreator is a special class found inside the DeepSpaceLabs.EditorCore namespace. You will need to add a using statement or type out the full namespace with the class name when declaring the variable in order to use it.