> For the complete documentation index, see [llms.txt](https://docs.febucci.com/text-animator-godot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.febucci.com/text-animator-godot/effects/create-your-own-effects/writing-custom-effects-c.md).

# Writing Custom Effects (C#)

You can easily program custom Effects via C#.

***

## 1. Effect Base Class

All you need to do is inherit from the base `Febucci.UI.TextAnimationEffect`.

{% hint style="warning" %}
Scripting API will be available soon!
{% endhint %}

```csharp
public partial class CustomEffect : TextAnimationEffect
{
    //[...]
```

There are also some useful classes already available for you that you can view from the API, like the “BehaviorEffectBase” or “AppearanceEffectBase” which are intended for each effect category, “SineBehaviorEffectsBase” which already handles modifiers such as “a, f, w” and more.

## 2. Attributes

Since you’re creating a Resource, make sure to add the needed attributes as well in order to instance and serialize them:

```csharp
[Tool, GlobalClass]
public partial class CustomEffect : TextAnimationEffect
{
    //[...]
```

{% hint style="danger" %}
Both attributes are **mandatory** to see the new effects in the resource explorer of a `TextAnimationsDatabase`.
{% endhint %}

***

## 3. Modifiers Methods

Since effects can be affected by “[Modifiers](/text-animator-godot/effects/add-effects-to-your-texts/modifiers.md)”, you can override the following methods to handle them in your animations:

These methods will be applied, in order, before the animation.

### 3.1 Accessing TextAnimator

You can access the current TextAnimator from your effect by calling the property:

```csharp
public TextAnimator TextAnimator { get; private set; }
```

### 3.1 ResetContext

```csharp
override void OnResetContext()
```

You can use this method to reset your animation’s variables to their initial state.\
For example, in the inspector you can publicly expose a variable called `baseSpeed`, but in your effect only use `currentSpeed` and have that variable be `currentSpeed=baseSpeed` inside this method.

### 3.2 SetModifier

```csharp
override void SetModifier(ModifierInfo modifierInfo, CharFXTransform charTransform)
```

You can use this method to apply a modifier to your variables.

For example this will multiply the `currentSpeed` value by the `s` modifier (if there is any).

```csharp
public override void SetModifier(ModifierInfo modifierInfo, CharFXTransform charTransform)
{
    switch (modifierInfo.name)
    {
        case "s": currentSpeed *= modifier.value; break;
    }
}
```

👍🏻 If you want to create a Behavior effect that has three modifiers such as “CurrentAmplitude”, “CurrentFrequency” and “CurrentWaveSize”, you can create a class that inherits from `BehaviorSineBase` which will handle them for you.

## 4. Animation Methods

Here are a few methods that you can override to create your custom animations.

### 4.1 CanApplyEffectTo

```csharp
override bool CanApplyEffectTo(CharFXTransform charFx)
```

Used to check if the effect can be applied to the current letter. For example if you’re creating an appearance effect, which only applies if a character passed time is within the effect’s durattion (but in that case you can inherit from “AppearanceScriptableBase” and have it handle that for you).

You can go beyond that, for example check if the character is a number or a letter, or their word index and much more.

### 4.2 OnProcessCustomFx

```csharp
override void OnProcessCustomFx(CharFXTransform charFX)
```

Main method to apply an animation to a letter, called if “OnProcessCustomFx” returned true.

* `charFX` is reset every frame so you’re expected to modify its values in order to animate a letter.

## ✅ Done! <a href="#done" id="done"></a>

**You’ve completed all the steps necessary, yay!**\
The more effects you add, the more this process will sound familiar and simpler.

{% hint style="warning" %}
Remember to create your effect ScriptableObject in the ProjectView, and add it to a database.

You can read more here: [Databases](/text-animator-godot/effects/add-effects-to-your-texts/databases.md)
{% endhint %}

{% hint style="success" %}
👍🏻 You can always take a look at the  built-in effects classes and see how they’re implemented.
{% endhint %}

**Have fun applying your effects!**
