# CustomEffect

### Description

Custom Effects are a way to add additional functionality to each [StatusEffectData](https://maraudical.gitbook.io/status-effect-framework/1.4.0/type-specifics/scriptable-objects/statuseffectdata). 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.

### UniTask Support

Note that if you have [UniTask](https://docs.unity3d.com/ScriptReference/Coroutine.html) in your project then the CustomEffect 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 EffectEnd abstract method because one 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).

### Abstract Methods

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

### Example

```csharp
using System.Collections;
using UnityEngine;
// Use StatusEffects.Custom namespace for organization.
namespace StatusEffects.Custom
{
    // Setup scriptable object in create menu.
    [CreateAssetMenu(fileName = "Damage Over Time Effect", menuName = "Status Effect Framework/Custom Effects/Damage Over Time", order = 1)]
    public class DamageOverTimeEffect : CustomEffect
    {
        // Unique value for this effect example
        public float intervalSeconds = 1f;

        public override IEnumerator Effect<T>(T monoBehaviour, StatusEffect statusEffect)
        {
            // Use your own character/entity class for this
            if (monoBehaviour.TryGetComponent(out ExampleEntity entity))
                for (; ; )
                {
                    entity.health -= statusEffect.data.baseValue;
                    yield return new WaitForSeconds(intervalSeconds);
                }
        }

        public override void EffectEnd<T>(T monoBehaviour, StatusEffect statusEffect) { }
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://maraudical.gitbook.io/status-effect-framework/1.4.0/type-specifics/scriptable-objects/customeffect.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
