Injection Attribute Types

Pro Only: Weaver Lite allows you to try out this feature in the Unity Editor, but it will not be available in a runtime build unless you purchase Weaver Pro.

There are several different kinds of injection attributes included with Weaver and you can implement your own by creating a class that inherits from InjectionAttribute or AssetInjectionAttribute.

Icon Attribute Description
AssetReference Assigns an asset reference directly to the attributed member.
If you want to ensure that the target asset doesn't get loaded until it is actually needed (instead of loading it on startup) you can use Asset<T> as the field type (where T is the asset type). Note that this requires the asset to be in a Resources folder.
AssetInstance Instantiates a copy of the target asset in the scene, calls DontDestroyOnLoad on it, and assigns it to the attributed member.
AssetPool Assigns an ObjectPool<T> which creates new objects by instantiating the target asset. See the Object Pooling section for more information.
Pref Doesn't reference an asset, so it inherits directly from InjectionAttribute rather than AssetInjectionAttribute. Simply assigns a value loaded from PlayerPrefs on startup and saves the value back to PlayerPrefs on shutdown. See Pref Injection for more details.
EditorPref [Editor-Only] Same as Pref but uses EditorPrefs instead.

When you apply any InjectionAttribute you can specify certain optional properties in its constructor to modify its behaviour. For example: [AssetReference(Optional = true)]. Each specific attribute type may also have additional optional properties.

You can also use the [OnInjectionComplete] attribute on a static parameterless method to have Weaver automatically call it on startup after all fields have been injected. This is useful if you want to imemdiately do something with multiple injected values since you can't be sure of the order they will be assigned.