# OnCollisionExit(Collision)

> OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.

## Definition

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

## OnCollisionExit()

```csharp
public void OnCollisionExit(Collision collision)
```

### Parameters

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

### Remarks

`OnCollisionExit` receives an instance of the [Collision](/engine/7000.0/script-reference/unityengine/collision.md) class as the `collision` parameter. This parameter contains information about the collision such as contact points and impact velocity. If you don't use this collision data in your `OnCollisionExit` callback, leave out the `collision` parameter from the method declaration to avoid unnecessary calculations. **Note:** Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached. Collision events are sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions. If one of the objects involved in the collision is deactivated or destroyed before the objects separate, `OnCollisionExit` isn't called. Physics backends report collision enter, stay, and exit, so Unity sends `OnCollisionExit` when the two colliders separate. Deactivation and destruction don't produce an exit message, for two different reasons: - If you disable 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 collision events. - If you destroy a collider, there is nothing left to report to. The destroyed object can't receive the message, and the [Collision](/engine/7000.0/script-reference/unityengine/collision.md) that `OnCollisionExit` supplies describes a collider that no longer exists. Unity could send `OnCollisionExit` in these cases by storing and maintaining a record of every touching pair in the scene, but maintaining that record costs CPU time and memory in every project, including projects that don't need this behavior. If your logic depends on `OnCollisionExit` being called whenever contact ends, including when an object is deactivated or destroyed, you need to implement additional logic, such as handling cleanup in [MonoBehaviour.OnDisable()](/engine/7000.0/script-reference/unityengine/monobehaviour/ondisable.md) or [MonoBehaviour.OnDestroy()](/engine/7000.0/script-reference/unityengine/monobehaviour/ondestroy.md), or recording contacts yourself and reconciling them each physics step. If you record contacts yourself, 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. Subscribe to [Physics.ContactEvent](/engine/7000.0/script-reference/unityengine/physics/contactevent.md) to read contacts from each simulation step, rather than relying on per-object messages. Unity doesn't report every contact in the scene through this event: a collider contributes contacts only if you set [Collider.providesContacts](/engine/7000.0/script-reference/unityengine/collider/providescontacts.md) to `true` on it, or it has a [MonoBehaviour](/engine/7000.0/script-reference/unityengine/monobehaviour.md) with an `OnCollisionStay` method attached, so enable `providesContacts` on the colliders you want to track. Each [ContactPair](/engine/7000.0/script-reference/unityengine/contactpair.md) identifies its colliders by [ContactPair.colliderEntityId](/engine/7000.0/script-reference/unityengine/contactpair/colliderentityid.md) and [ContactPair.otherColliderEntityId](/engine/7000.0/script-reference/unityengine/contactpair/othercolliderentityid.md), so you can match contacts against your own records. For more information, refer to [OnCollision events](/engine/7000.0/manual/physics-section/physics-overview/collision-section/collider-interactions/oncollision.md). `OnCollisionExit` can be a [coroutine](/engine/7000.0/manual/scripting/coroutines-section/coroutines.md).

### Examples

```csharp

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour
{
    void OnCollisionExit(Collision other)
    {
        print("No longer in contact with " + other.transform.name);
    }
}
```
