> 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/module.md).

# Module

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

### Description

Modules are a way to add additional functionality to each [StatusEffectData](/status-effects-framework/2.0.0/type-specifics/scriptable-objects/statuseffectdata.md). Create one by simply inheriting from the Module class and implementing the required methods.&#x20;

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

Truthfully anything can be done with them as they are just an inheritable abstract class with a coroutine, allowing for unlimited functionality. It is **highly recommended** to take a look at the [samples](https://github.com/maraudical/StatusEffectsFramework-Unity/tree/main/Samples) for an idea of how to use them.

{% hint style="info" %}
Make sure to checkout [ModuleInstance](/status-effects-framework/2.0.0/type-specifics/scriptable-objects/moduleinstance.md) to see how you can setup unique module data per [StatusEffectData](/status-effects-framework/2.0.0/type-specifics/scriptable-objects/statuseffectdata.md)!
{% endhint %}

### UniTask Support

Note that if you have [UniTask](https://docs.unity3d.com/ScriptReference/Coroutine.html) in your project then the Module will use [UniTasks](https://docs.unity3d.com/ScriptReference/Coroutine.html) over [Coroutines](https://docs.unity3d.com/ScriptReference/Coroutine.html). This is also included in the samples, but note that the only real difference is that there is no DisableModule abstract method because you can just wait until cancellation is requested on the [token](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken?view=net-8.0).

### Awaitable Support

Note that if you are using Unity 2023.1 or later then the Module will use [Awaitable](https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Awaitable.html) over [Coroutines](https://docs.unity3d.com/ScriptReference/Coroutine.html). Like [UniTask](https://docs.unity3d.com/ScriptReference/Coroutine.html) it is also included in the samples and the DisableModule abstract method is not used.

### Abstract Methods

<table data-header-hidden data-full-width="false"><thead><tr><th width="224"></th><th></th></tr></thead><tbody><tr><td>EnableModule</td><td>A <a href="https://docs.unity3d.com/ScriptReference/Coroutine.html">Coroutine</a> that is started when the <a href="/pages/OpUFQnv9JKaTU0cxnlHw">StatusEffect</a> begins.</td></tr><tr><td>DisableModule</td><td>A method that is invoked when the <a href="/pages/OpUFQnv9JKaTU0cxnlHw">StatusEffect</a> is stopped.</td></tr></tbody></table>

### Example

```csharp
using System.Collections;
using UnityEngine;
// Use StatusEffects.Modules namespace for organization.
namespace StatusEffects.Modules
{
    // Setup scriptable object in create menu.
    [CreateAssetMenu(fileName = "Damage Over Time Effect", menuName = "Status Effect Framework/Custom Effects/Damage Over Time", order = 1)]
    // This attribute will attach the module instance so 
    // that the interval time can be unique to each effect.
    [AttachModuleInstance(typeof(DamageOverTimeInstance))]
    public class DamageOverTimeEffect : CustomEffect
    {
        public override IEnumerator EnableModuleEnableModule(StatusManager manager, StatusEffect statusEffect, ModuleInstance moduleInstance)
        {
            // Note that for this module it uses a ModuleInstance 
            // to store a unique interval rate.
            DamageOverTimeInstance damageOverTimeInstance = moduleInstance as DamageOverTimeInstance;

            if (monoBehaviour.TryGetComponent(out ExampleEntity entity))
                // Infinite loop will be cancelled when coroutine is stopped.
                for (; ; )
                {
                    // Reduce health based on the Statu Effect base value.
                    entity.health -= statusEffect.data.baseValue;
                    // Wait for the interval before applying the damage again.
                    yield return new WaitForSeconds(damageOverTimeInstance.intervalSeconds);
                }
        }
        // You don't need to have anything in the disable method if you don't need to.
        public override void DisableModuleEnableModule(StatusManager manager, StatusEffect statusEffect, ModuleInstance moduleInstance) { }
}
```
