> For the complete documentation index, see [llms.txt](https://maraudical.gitbook.io/status-effects-framework/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://maraudical.gitbook.io/status-effects-framework/2.0.0/type-specifics/scriptable-objects/moduleinstance.md).

# ModuleInstance

<figure><picture><source srcset="/files/ltKZZuOEh6ekCoEG5ooO" media="(prefers-color-scheme: dark)"><img src="/files/F9bN9p5fTylodGPGMagG" alt="" width="188"></picture><figcaption></figcaption></figure>

### Description

ModuleInstances can be attached to Modules so that unique data can be selected per [StatusEffectData](/status-effects-framework/2.0.0/type-specifics/scriptable-objects/statuseffectdata.md).  Create one by simply inheriting from the ModuleInstance class.

{% hint style="danger" %}
You NEED to use the **StatusEffects.Modules** namespace like in the example below for both [Modules](/status-effects-framework/2.0.0/type-specifics/scriptable-objects/module.md) and ModuleInstances.
{% endhint %}

{% hint style="warning" %}
You do not need to add these to the create menu! As long as it is attached to a [Module](/status-effects-framework/2.0.0/type-specifics/scriptable-objects/module.md) using the attribute it will be created automatically.
{% endhint %}

As an example, say you needed a VFX prefab to be instantiated on each effect. Instead of having to create a unique VFXModule for each prefab that you need, just add the variables you need in the ModuleInstance and attach it to the [Module](/status-effects-framework/2.0.0/type-specifics/scriptable-objects/module.md) using the **AttachModuleInstance** attribute.

Now, every time you add a module to a [StatusEffectData](/status-effects-framework/2.0.0/type-specifics/scriptable-objects/statuseffectdata.md), it will instantiate those values for that effect making it so you only need to create one VFXModule scriptable object with any constant values and unique instance values will be displayed in the specific [StatusEffectData](/status-effects-framework/2.0.0/type-specifics/scriptable-objects/statuseffectdata.md).

<figure><img src="/files/LEwX4CQegg50TlKV79jo" alt=""><figcaption></figcaption></figure>

### Example

```csharp
using UnityEngine;
// Use StatusEffects.Modules namespace for organization.
namespace StatusEffects.Modules
{
    public class VFXInstance : ModuleInstance
    {
        public GameObject prefab;  
    }
}
```

### Example module to attach to

```csharp
using System.Collections;
using UnityEngine;
// Use StatusEffects.Modules namespace for organization.
namespace StatusEffects.Modules
{
    [CreateAssetMenu(fileName = "VFX Module", menuName = "Status Effect Framework/Modules/VFX", order = 1)]
    // This attribute will attach the module instance so 
    // that it can be created for each StatusEffectData.
    [AttachModuleInstance(typeof(VFXInstance))]
    public class VFXModule : Module
    {
        public override IEnumerator EnableModule<T>(T monoBehaviour, StatusEffect statusEffect, ModuleInstance moduleInstance)
        {
            VFXInstance VFXInstance = moduleInstance as VFXInstance;
            // Give the vfx the name of the prefab so it can be queried later
            Instantiate(VFXInstance.prefab, monoBehaviour.transform).name = VFXInstance.prefab.name;

            yield break;
        }

        public override void DisableModule<T>(T monoBehaviour, StatusEffect statusEffect, ModuleInstance moduleInstance) 
        {
            VFXInstance VFXInstance = moduleInstance as VFXInstance;
            // Find the VFX by name.
            Transform VFXTransform = monoBehaviour.transform.Find(VFXInstance.prefab.name);
            
            if (!VFXTransform)
                return;
            
            GameObject VFXGameObject = VFXTransform.gameObject;
            // Attempt to stop the particle system.
            if (VFXGameObject.TryGetComponent(out ParticleSystem particleSystem))
                particleSystem.Stop();
            
            VFXTransform.SetParent(null);
            // Destroy after a wait so that particles have time to fade out
            Destroy(VFXGameObject, 5);
        }
    }
}
```
