# OnStateUpdate

> Invoked on each update frame except for the first and last frame. Implement this message to execute custom logic on a state by state basis.

## Definition

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

## OnStateUpdate(Animator, AnimatorStateInfo, int)

Invoked on each update frame except for the first and last frame. Implement this message to execute custom logic on a state by state basis.

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

### Parameters

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

### Remarks

OnStateUpdate is invoked every frame for the currently evaluated state, as well the next state and the interrupted state if applicable.

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

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

Invoked on each update frame except for the first and last frame. Implement this message to execute custom logic on a state by state basis.

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

### Parameters

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

### Remarks

OnStateUpdate is invoked every frame for the currently evaluated state, as well the next state and the interrupted state if applicable.

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