# OnTriggerExit(Collider)

> Called when a collider stops touching a trigger collider.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/7000.0/script-reference/unityengine.md)

## OnTriggerExit()

```csharp
public void OnTriggerExit(Collider collider)
```

### Parameters

**** (\[Collider]\(/engine/7000.0/script-reference/unityengine/collider)):&#x20;

### Remarks

`OnTriggerExit` is called during whichever iteration of the physics `FixedUpdate` loop Unity detects that a collider is no longer touching a trigger it was previously touching. Both GameObjects must contain a [Collider](/engine/7000.0/script-reference/unityengine/collider.md) component. At least one of the colliders must be a trigger collider and at least one must be a physics body collider. For more information, refer to [OnTrigger events](/engine/7000.0/manual/physics-section/physics-overview/collision-section/collider-interactions/ontrigger.md). Both the trigger and the collider that touches the trigger receive `OnTriggerExit` if they have implemented it. Trigger events are sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions. Deactivating or destroying either collider while they overlap doesn't cause an `OnTriggerExit` message to be sent. Physics backends report only that two shapes started or stopped overlapping, so Unity sends `OnTriggerExit` when the two colliders move apart. Deactivation and destruction don't produce an exit message, for two different reasons: - If you deactivate a collider, or the GameObject it belongs to, the message would report a collider that is no longer in the simulation. Deactivating a GameObject also stops its scripts from receiving messages at all, unlike disabling a `MonoBehaviour`, which still receives trigger events. - If you destroy a collider, there is nothing left to report to. The destroyed object can't receive the message, and the collider that `OnTriggerExit` supplies as its argument no longer exists. Unity could send `OnTriggerExit` in these cases by storing and maintaining a record of every overlapping pair in the scene, but maintaining that record costs CPU time and memory in every project, including projects that don't need this behavior. Handle these cases in your own scripts instead: record the colliders that enter each trigger, then treat a recorded collider as having exited when [MonoBehaviour.OnDisable()](/engine/7000.0/script-reference/unityengine/monobehaviour/ondisable.md) or [MonoBehaviour.OnDestroy()](/engine/7000.0/script-reference/unityengine/monobehaviour/ondestroy.md) runs on it, or when it is no longer active. Record each collider's [EntityId](/engine/7000.0/script-reference/unityengine/entityid.md), and any data you need about it, while the collider is still alive. After Unity destroys a collider, the reference to it compares equal to `null`, so you can't read any values from it and you can't rely on it to report its own `EntityId`. For an example script, refer to [OnTrigger events](/engine/7000.0/manual/physics-section/physics-overview/collision-section/collider-interactions/ontrigger.md). `OnTriggerExit` can be a coroutine.

### Examples

```csharp

// Destroy everything that leaves the trigger

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    void OnTriggerExit(Collider other)
    {
        Destroy(other.gameObject);
    }
}
```
