# EffectInstance

> A ProcessorInstance that processes audio data.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEngine.Audio](/engine/6000.7/script-reference/unityengine/audio.md)
* **Assembly:** UnityEngine.AudioModule
* **Implements:** [IEquatable\<EffectInstance>](https://learn.microsoft.com/dotnet/api/system.iequatable-1)

```csharp
public struct EffectInstance : IEquatable<EffectInstance>
```

## Remarks

An [EffectInstance](/engine/6000.7/script-reference/unityengine/audio/effectinstance.md) reads audio from an input buffer, transforms it, and writes the result to an output buffer. You can define the EffectInstance through implementing the [EffectInstance.IControl\<TProcessor>](/engine/6000.7/script-reference/unityengine/audio/effectinstance/icontrol1.md) and [EffectInstance.IRealtime](/engine/6000.7/script-reference/unityengine/audio/effectinstance/irealtime.md) interfaces, which defines the control and real-time thread behavior respectively.

To use an effect in a scene, implement [IAudioEffect](/engine/6000.7/script-reference/unityengine/audio/iaudioeffect.md) on a [MonoBehaviour](/engine/6000.7/script-reference/unityengine/monobehaviour.md) and add the component to the same GameObject as an [AudioSource](/engine/6000.7/script-reference/unityengine/audiosource.md). The [AudioSource](/engine/6000.7/script-reference/unityengine/audiosource.md) auto-discovers [IAudioEffect](/engine/6000.7/script-reference/unityengine/audio/iaudioeffect.md) components on its GameObject, and instantiates and manages their [EffectInstance](/engine/6000.7/script-reference/unityengine/audio/effectinstance.md)s for you.

It is also possible to create your own effects through code using [ControlContext.AllocateEffect](/engine/6000.7/script-reference/unityengine/audio/controlcontext/allocateeffect.md), for example to run an effect nested inside another processor. Interacting with an instantiated effect depends on the ownership of the [EffectInstance](/engine/6000.7/script-reference/unityengine/audio/effectinstance.md): If the effect has been created from an [AudioSource](/engine/6000.7/script-reference/unityengine/audiosource.md), you would interact with it through the instance obtained from [AudioSource.GetEffectInstance](/engine/6000.7/script-reference/unityengine/audiosource/geteffectinstance.md).

Additional Resources: [IAudioEffect](/engine/6000.7/script-reference/unityengine/audio/iaudioeffect.md), [ControlContext.AllocateEffect](/engine/6000.7/script-reference/unityengine/audio/controlcontext/allocateeffect.md)

The following example implements a gain effect and exposes it as a component you can add to the GameObject of an AudioSource.

## Examples

```csharp
[BurstCompile(CompileSynchronously = true)]
struct Realtime : EffectInstance.IRealtime
{
    // Fixed attenuation applied to every sample.
    private const float k_Gain = 0.5f;

    // Called when the real-time side of the graph updates (e.g., new control data available).
    // Keep this method allocation-free and exception-free.
    public void Update(UpdatedDataContext context, Pipe pipe) { }

    public EffectInstance.Result Process(
        in RealtimeContext context,
        ChannelBuffer inputBuffer,
        ChannelBuffer outputBuffer,
        EffectInstance.Arguments args)
    {
        // Scale every input sample and write it to the output buffer.
        // Always write every output sample: the output buffer starts undefined.
        for (int frame = 0; frame < inputBuffer.frameCount; frame++)
        {
            for (int ch = 0; ch < inputBuffer.channelCount; ch++)
                outputBuffer[ch, frame] = inputBuffer[ch, frame] * k_Gain;
        }

        return default;
    }
}
```

## Methods

| Method                                                                                         | Description                                                                                                                                                                                                             |
| ---------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Configure](/engine/6000.7/script-reference/unityengine/audio/effectinstance/configure.md)     | Manually reconfigure this [EffectInstance](/engine/6000.7/script-reference/unityengine/audio/effectinstance.md) with the given [AudioConfiguration](/engine/6000.7/script-reference/unityengine/audioconfiguration.md). |
| [Equals](/engine/6000.7/script-reference/unityengine/audio/effectinstance/equals.md)           | Checks if this instance equals a given object.                                                                                                                                                                          |
| [GetHashCode](/engine/6000.7/script-reference/unityengine/audio/effectinstance/gethashcode.md) | Retrieves a hash code based on this instance.                                                                                                                                                                           |
| [Process](/engine/6000.7/script-reference/unityengine/audio/effectinstance/process.md)         | Manually process this particular [EffectInstance](/engine/6000.7/script-reference/unityengine/audio/effectinstance.md).                                                                                                 |

## Operators

| Operator                                                                                             | Description                                                                                                                                                                                                                        |
| ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [operator ==](/engine/6000.7/script-reference/unityengine/audio/effectinstance/op-equality.md)       | Checks if two instances are equal.                                                                                                                                                                                                 |
| [ProcessorInstance](/engine/6000.7/script-reference/unityengine/audio/effectinstance/op-implicit.md) | Convert this [EffectInstance](/engine/6000.7/script-reference/unityengine/audio/effectinstance.md) to its more general [ProcessorInstance](/engine/6000.7/script-reference/unityengine/audio/processorinstance.md) representation. |
| [operator !=](/engine/6000.7/script-reference/unityengine/audio/effectinstance/op-inequality.md)     | Checks if two instances are not equal.                                                                                                                                                                                             |

## Structs

| Struct                                                                                                                      | Description                                                                                                                                           |
| --------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| [EffectInstance.Arguments](/engine/6000.7/script-reference/unityengine/audio/effectinstance/arguments.md)                   | Additional arguments passed to the EffectInstance.IRealtime.Process method.                                                                           |
| [EffectInstance.CreationParameters](/engine/6000.7/script-reference/unityengine/audio/effectinstance/creationparameters.md) | Additional parameters and initialization state for creating an [EffectInstance](/engine/6000.7/script-reference/unityengine/audio/effectinstance.md). |
| [EffectInstance.Result](/engine/6000.7/script-reference/unityengine/audio/effectinstance/result.md)                         | The result returned from an EffectInstance.IRealtime.Process call.                                                                                    |
| [EffectInstance.Setup](/engine/6000.7/script-reference/unityengine/audio/effectinstance/setup.md)                           | Per-instance setup an effect reports back from EffectInstance.IControl\<TProcessor>.Configure.                                                        |
| [EffectInstance.Sidechain](/engine/6000.7/script-reference/unityengine/audio/effectinstance/sidechain.md)                   | Placeholder for future sidechain wiring and layout information.                                                                                       |

## Interfaces

| Interface                                                                                                             | Description                                                                                                                                                                           |
| --------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [EffectInstance.ICapabilities](/engine/6000.7/script-reference/unityengine/audio/effectinstance/icapabilities.md)     | Static capabilities an effect declares up front.                                                                                                                                      |
| [EffectInstance.IControl\<TProcessor>](/engine/6000.7/script-reference/unityengine/audio/effectinstance/icontrol1.md) | The control interface an implementation of an [EffectInstance](/engine/6000.7/script-reference/unityengine/audio/effectinstance.md) must implement on a struct to be fully formed.    |
| [EffectInstance.IRealtime](/engine/6000.7/script-reference/unityengine/audio/effectinstance/irealtime.md)             | The processing interface an implementation of an [EffectInstance](/engine/6000.7/script-reference/unityengine/audio/effectinstance.md) must implement on a struct to be fully formed. |
