> For the complete documentation index, see [llms.txt](https://malbersanimations.gitbook.io/animal-controller/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://malbersanimations.gitbook.io/animal-controller/global-components/trigger-proxy.md).

# Trigger Proxy

Last updated AC v1.5.3

## Overview

This component is perfect for doing quick **OnTriggerEnter** / **OnTriggerExit** logics. The power of this component is that when an Object has several colliders inside a hierarchy, you can use the **On GameObject Enter/Exit** events to find which is the Root GameObject that really entered or exited the Trigger.

It keeps two sets at runtime: every **Collider** currently inside, and every **GameObject** those colliders belong to. The GameObject events only fire once per object, no matter how many of its colliders are inside.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FaAYzFW2d4DRcXhNHHitz%2Fimage.png?alt=media&#x26;token=79d5de2c-0a59-400d-a636-0be457ca1982" alt=""><figcaption></figcaption></figure>

The inspector is split into three tabs: **General**, **Events** and **Reactions**.

## Requirements

This component requires any type of collider to work.

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-MYh1V8S0XP177f7u70g%2F-MYh1g7MkcOSmgZedUlv%2Fimage.png?alt=media\&token=5d21d8f1-1d32-4788-9676-824e4999f20b)

The Collider needs to be set as **Trigger**. The component sets `isTrigger` on the collider it uses on `Awake`, and enables that collider again every time the Trigger Proxy is enabled.

{% hint style="info" %}
Unity does **not** send an `OnTriggerExit` for a collider that is disabled or destroyed while it is still inside a trigger. The Trigger Proxy sweeps for those (see [Sweep Interval](#sweep-interval)) and releases them itself, so the Exit events still fire.
{% endhint %}

## How it Works

1. A collider enters. It is checked against **Layer**, **Trigger Interaction**, **Tags**, **Ignore Static** and the **Conditions** list. Anything that fails is ignored.
2. The collider is added to the internal collider set and **On Trigger Enter** fires.
3. The object that owns the collider is resolved. If it was not already tracked, **On GameObject Enter** fires for it.
4. On exit, the collider is removed. **On Trigger Exit** fires. **On GameObject Exit** only fires when the *last* collider of that object has left.
5. When the trigger becomes empty, **On Empty** fires.

## Parameters

### General

#### ID

ID of the Trigger Proxy. Use it to identify which proxy fired when several of them share a listener. Default is `-1`.

The **Debug** toggle sits next to it (see [Debug](#debug)).

#### Trigger

The **Collider** used as the trigger. When left empty it is filled with the first collider found on the same GameObject.

#### Layer

Which Layers will be checked on the entering colliders. Default is **Everything**.

{% hint style="warning" %}
A Layer set to **Nothing** silently detects no colliders at all.
{% endhint %}

#### Trigger Interaction

What to do with other Triggers entering this Trigger: **Collide** or **Ignore**. Default is **Ignore**.

#### Use On Trigger Stay

If true, the proxy checks its contents every frame and invokes **On Trigger Stay** and **On GameObject Stay** on everything inside. This also turns on the Stay Reactions and makes the disabled-collider sweep run every frame.

#### Sweep Interval

Seconds between sweeps for colliders that were disabled or destroyed while inside the Trigger, which Unity never reports with an Exit. `0` turns the sweep off. Default is `0.25`.

Only shown when **Use On Trigger Stay** is **off** — with Stay on, the sweep already happens every frame.

#### One Time Use

The Trigger is disabled the first time it finds a valid collider.

{% hint style="info" %}
When One Time Use disables the proxy, the colliders inside are released **silently**: no Exit events are fired. Firing them would undo, on the same frame, the Enter that just consumed the trigger.
{% endhint %}

#### Ignore Static

Do not interact with static colliders.

#### Tags

Malbers [Tags](/animal-controller/scriptable-architecture/scriptables/tags.md) that are allowed to use this Trigger Proxy. Leave it empty to allow everything.

#### Conditions

Extra [Conditions](/animal-controller/global-components/conditions.md) to filter the colliders entering the trigger. The Dynamic Target of the list is the **entering Collider**.

#### Debug

The bug icon next to the ID. When active it logs the colliders and GameObjects entering and exiting the trigger, and in Play Mode the inspector lists everything currently inside.

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-MYh48ZWabD1R-AgCmlR%2F-MYh4CXbshdP5LW26tNT%2FU6LpC9ITL7.gif?alt=media\&token=3e924610-7076-4d13-a8b7-f5e3f976b21a)

## Events

On the **Events** tab.

### On Trigger Enter

Invoked when a valid collider enters the trigger. Sends the **Collider**.

### On Trigger Exit

Invoked when a collider exits the trigger. Sends the **Collider**.

{% hint style="info" %}
When a collider was destroyed while inside, this event is invoked with a **null** Collider. Listeners that resolve something from the collider must handle that case.
{% endhint %}

### On Empty

Invoked when the Trigger Proxy has nothing left inside it, and when the trigger is reset.

### On Trigger Stay

Invoked every frame for every collider inside. Only shown when **Use On Trigger Stay** is on.

### On GameObject Enter

Invoked when a GameObject enters the trigger. Sends the **GameObject**. Fires once per object, even when several of its colliders enter.

### On GameObject Exit

Invoked when a GameObject exits the trigger. Sends the **GameObject**. Fires only when the last collider of that object has left.

### On GameObject Stay

Invoked every frame for every GameObject inside. Only shown when **Use On Trigger Stay** is on.

## Reactions

On the **Reactions** tab. Each one is a [Reaction](/animal-controller/main-components/reactions.md) applied on the object that triggered it, and runs alongside the matching Event.

| Reaction                  | Applied on                         | Shown when          |
| ------------------------- | ---------------------------------- | ------------------- |
| Trigger Enter Reaction    | The entering Collider              | Always              |
| Trigger Exit Reaction     | The exiting Collider               | Always              |
| Trigger Stay Reaction     | Every Collider inside, per frame   | Use On Trigger Stay |
| GameObject Enter Reaction | The entering GameObject            | Always              |
| GameObject Exit Reaction  | The exiting GameObject             | Always              |
| GameObject Stay Reaction  | Every GameObject inside, per frame | Use On Trigger Stay |

`[Insert Image - The Reactions tab of the Trigger Proxy with the six Reaction slots]`

## Public Methods

Callable from UnityEvents or code:

* `Activate(bool)` — enable or disable the proxy. Disabling fires Exit for everything inside.
* `ResetTrigger()` — release every collider and GameObject inside without firing Exit events.
* `RefreshColliders()` — run the disabled/destroyed collider sweep now.
* `CheckOntriggerStay()` — run one Stay pass manually.
* `SetLayer(LayerMask, QueryTriggerInteraction, Transform owner, MTags tags)` — reconfigure the proxy at runtime. Used by the components that create a proxy for you, such as the [Interactor](/animal-controller/global-components/interactor.md).
* `Active` — property mirroring `enabled`.
* `Owner` — the Transform the proxy belongs to. Defaults to its own Transform.

Code-level hooks (`System.Action`):

* `EnterTriggerInteraction` / `ExitTriggerInteraction` — `(GameObject, Collider, TriggerProxy)`.
* `OnActivated` — raised when the proxy is enabled, i.e. a new activation window. Listeners that remember what they already hit reset here.
