# OnStateEnter

> Invoked on the first update frame when a state machine evaluates this state. Implement this message to react to a new state starting.

## Definition

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

## OnStateEnter(Animator, AnimatorStateInfo, int)

Invoked on the first update frame when a state machine evaluates this state. Implement this message to react to a new state starting.

```csharp
public virtual void OnStateEnter(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

OnStateEnter is invoked when a transition to a state is initiated. It will be invoked after [OnStateUpdate](/engine/6000.6/script-reference/unityengine/statemachinebehaviour/onstateupdate.md) of the current state.

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

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

Invoked on the first update frame when a state machine evaluates this state. Implement this message to react to a new state starting.

```csharp
public virtual void OnStateEnter(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

OnStateEnter is invoked when a transition to a state is initiated. It will be invoked after [OnStateUpdate](/engine/6000.6/script-reference/unityengine/statemachinebehaviour/onstateupdate.md) of the current state.

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