The AssetInstance module makes it possible to connect ScriptableObjects with a MonoBehaviours. Any reference to one of the two can quickly find the other. It allows you to find and call methods of MonoBehaviours in the scene, with only a reference to their linked ScriptableObject.
Within DuskModules, AssetInstance is mainly used by the ObjectPooling module. It ensures that every pool ScriptableObject automatically connects to a behaviour of the object pool. It is also used to target objects in additive scenes or prefabs which cannot be referenced without custom search code.
AssetInstance has no dependencies.
InstanceAsset is the base ScriptableObject, which you can inherit to write your own InstanceAssets. It requires type parameters of its own class, and the class of the InstanceBehaviour that represents it.Â
You can use InstanceAsset.instance to return the MonoBehaviour tied to this ScriptableObject. If it exists in the scene, it will find it. If it doesn't, it will automatically instantiate it into the currently active scene. Once linked, the reference is cached to save performance.
This means that you can reference the asset anywhere within your project, with the guarantee that you can fetch the behaviour instance of the asset at any time. When automatically created, the InstanceBehaviour is placed on an otherwise empty GameObject.
A variant of InstanceAsset, which instantiates a prefab instead of an empty game object. This can be preferred in case you want the behaviour object to include other components or objects.
InstanceBehaviour is the base MonoBehaviour, which you can inherit to write your own InstanceBehaviours. It requires type parameters of its own class, and the class of the InstanceBehaviour that represents it.
You can use InstanceBehaviour.asset to return the ScriptableObject tied to this MonoBehaviour. You can place InstanceBehaviours into your scene manually, and designate which AssetInstance they are tied to using the Editor Inspector GUI.
Don't forget to add using DuskModules.AssetInstance; to any script using the module.