# OnStateExit

> Invoked on the last update frame when a state machine evaluates this state. Implement this message to react to a state ending.

## Definition

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

## OnStateExit(Animator, AnimatorStateInfo, int)

Invoked on the last update frame when a state machine evaluates this state. Implement this message to react to a state ending.

```csharp
public virtual void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
```

### Parameters

**** (\[Animator]\(/engine/6000.6/script-reference/unityengine/animator)): The Animator evaluating this state machine.**** (\[AnimatorStateInfo]\(/engine/6000.6/script-reference/unityengine/animatorstateinfo)): **** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The current layer being evaluated.

### Remarks

OnStateExit is invoked when a transition to a state has completed or has been interrupted. It will be invoked before [OnStateUpdate](/engine/6000.6/script-reference/unityengine/statemachinebehaviour/onstateupdate.md) of the next state.

**Note**: OnStateExit may be invoked multiple times on the same state if that state is synchronized on multiple layers.

## OnStateExit(Animator, AnimatorStateInfo, int, AnimatorControllerPlayable)

Invoked on the last update frame when a state machine evaluates this state. Implement this message to react to a state ending.

```csharp
public virtual void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex, AnimatorControllerPlayable controller)
```

### Parameters

**** (\[Animator]\(/engine/6000.6/script-reference/unityengine/animator)): The Animator evaluating this state machine.**** (\[AnimatorStateInfo]\(/engine/6000.6/script-reference/unityengine/animatorstateinfo)): **** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The current layer being evaluated.**** (\[AnimatorControllerPlayable]\(/engine/6000.6/script-reference/unityengine/animations/animatorcontrollerplayable)):&#x20;

### Remarks

OnStateExit is invoked when a transition to a state has completed or has been interrupted. It will be invoked before [OnStateUpdate](/engine/6000.6/script-reference/unityengine/statemachinebehaviour/onstateupdate.md) of the next state.

**Note**: OnStateExit may be invoked multiple times on the same state if that state is synchronized on multiple layers.
