Defining a Procedural Asset

Pro Only: Weaver Lite allows you to try out procedural assets in the Unity Editor, but the Asset Injection will not be available in a runtime build unless you purchase Weaver Pro. You can still use the generated assets as regular assets though.

To define a procedural asset, you simply make an Asset Injection field, then give it a [ProceduralAsset] attribute and add a static method called GenerateX, where X is the name of the field. For example:

[AssetReference]
[ProceduralAsset]
public static readonly GameObject Prefab;

private static GameObject GeneratePrefab()
{
    var gameObject = new GameObject();// It will be called "Prefab" if we don't give it a name.
    // Add components and scripts, child objects, instantiate a model, etc.
    return gameObject;
}
  • You can use any Asset Injection Attribute for a procedural asset depending on how you want to use it at runtime.
  • You can use a procedural asset just like any other asset once it is generated. You can drag and drop a procedural prefab from the project window into a scene and it will update all instances whenever you regenerate it. Or you can use it in code just like any other injected asset.
  • You can make a procedural asset of any type derived from UnityEngine.Object, such as GameObject, Component, ScriptableObject, Mesh, TextAsset, Texture, or AudioClip. Some asset types have special rules for the way they are generated, see Asset Generators for more details.

Editor-Only Functionality

If your generator method uses any functionality only available in the Unity editor, you will need to use conditional compilation (#if UNITY_EDITOR and #endif) around such functionality to be able to build your project without errors. If you don’t need to use your generator method at runtime, you can put it around the whole method. Or if you don't even want to use the injected reference at runtime you can mark the Asset Injection attribute as EditorOnly = true in its constructor and put the #if around the field as well.