Asset Generators

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.

By default, a procedural asset is saved using AssetDatabase.CreateAsset once your generator method returns it. Unfortunately, this doesn’t work for some asset types; a GameObject must be saved using the PrefabUtility class, a Texture must be encoded in a specific image format (such as png), and so on. This is what Asset Generators are for:

  • You don’t need to call an Asset Generator yourself; Weaver will automatically pick the one that’s most appropriate for each asset type. However, you do need to be aware that certain asset types use different rules than others.
  • Each Asset Generator targets a specific asset type, for which it defines the default file extension (which is used if you don’t specify a FileExtension in the [ProceduralAsset] attribute), as well as the return type and parameters you must use for the generator method. Weaver currently includes 5 Asset Generators:
Class Name Asset Type File Extension Return Type Parameters
AssetGenerator<T> Object .asset T ()
PrefabGenerator GameObject* .prefab GameObject ()
TextureGenerator Texture2D .png Texture2D ()
TextGenerator TextAsset .txt void (System.Text.StringBuilder)
ScriptGenerator MonoScript .cs void (System.Text.StringBuilder)
AssetListGenerator AssetListBase .asset IEnumerable<T> ()
  • *PrefabGenerator is also used for Component types.
  • You can define your own Asset Generator by making a class that inherits from Weaver.AssetGenerator<T>. Weaver will automatically use your class whenever it generates a procedural asset of the specified type T.
  • The Procedural Assets panel in the Weaver Window has a foldout to show the details of all Asset Generator types currently in your project.