# AnimatorState

> Represents a state in a state machine.

## Definition

* **Type:** Class
* **Namespace:** [UnityEditor.Animations](/engine/6000.6/script-reference/unityeditor/animations.md)
* **Assembly:** UnityEditor.CoreModule
* **Inherits from:** [Object](/engine/6000.6/script-reference/unityengine/object.md)

```csharp
[HelpURL("class-State")]
public sealed class AnimatorState : Object
```

## Remarks

Each state contains an ([AnimationClip](/engine/6000.6/script-reference/unityengine/animationclip.md) or a [BlendTree](/engine/6000.6/script-reference/unityeditor/animations/blendtree.md)) which plays while the character is in the state. When a state transition is triggered, the character adopts a new state. The ([AnimationClip](/engine/6000.6/script-reference/unityengine/animationclip.md) or [BlendTree](/engine/6000.6/script-reference/unityeditor/animations/blendtree.md)) for the new state takes over.

The following example illustrates how to create a simple state machine using an editor script. It creates three states, "Idle", "Run", and "Jump", and transitions between them. This example does not set the [Motion](/engine/6000.6/script-reference/unityengine/motion.md). You can create a new state with [AnimatorController.AddMotion](/engine/6000.6/script-reference/unityeditor/animations/animatorcontroller/addmotion.md), or you can assign a motion to an existing state using [AnimatorState.motion](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/motion.md).

```csharp
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;

static class AnimatorStateExample
{
    [MenuItem("Example/Create Simple State Machine")]
    static void CreateSimpleController()
    {
        // Create the controller
        var controllerPath = AssetDatabase.GenerateUniqueAssetPath("Assets/SimpleController.controller");
        var controller = AnimatorController.CreateAnimatorControllerAtPath(controllerPath);

        var stateMachine = controller.layers[0].stateMachine;

        // Create the states. First state (Idle) becomes the default state
        var idleState = stateMachine.AddState("Idle", new Vector2(300, 200));
        var runState = stateMachine.AddState("Run", new Vector2(150, 350));
        var jumpState = stateMachine.AddState("Jump", new Vector2(450, 350));

        // Create the transition parameters
        controller.AddParameter("Speed", AnimatorControllerParameterType.Float);
        controller.AddParameter("Jump", AnimatorControllerParameterType.Trigger);

        // Create the transitions
        var idleToRun = idleState.AddTransition(runState);
        idleToRun.AddCondition(AnimatorConditionMode.Greater, 0.1f, "Speed");

        var runToIdle = runState.AddTransition(idleState);
        runToIdle.AddCondition(AnimatorConditionMode.Less, 0.1f, "Speed");

        var runToJump = runState.AddTransition(jumpState);
        runToJump.AddCondition(AnimatorConditionMode.If, 0, "Jump");
        runToJump.duration = 0;

        var jumpToRun = jumpState.AddTransition(runState);
        jumpToRun.duration = 0;

        var idleToJump = idleState.AddTransition(jumpState);
        idleToJump.AddCondition(AnimatorConditionMode.If, 0, "Jump");
    }
}
```

Additional Resources: [AnimatorController.AddMotion](/engine/6000.6/script-reference/unityeditor/animations/animatorcontroller/addmotion.md), [AnimatorStateMachine.AddState](/engine/6000.6/script-reference/unityeditor/animations/animatorstatemachine/addstate.md), [AnimatorStateMachine.states](/engine/6000.6/script-reference/unityeditor/animations/animatorstatemachine/states.md).

## Properties

| Property                                                                                                                         | Description                                                                                                          |
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| [behaviours](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/behaviours.md)                                 | The Behaviour list assigned to this state.                                                                           |
| [cycleOffset](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/cycleoffset.md)                               | Offset at which the animation loop starts. Useful for synchronizing looped animations. Units is normalized time.     |
| [cycleOffsetParameter](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/cycleoffsetparameter.md)             | The animator controller parameter that drives the cycle offset value.                                                |
| [cycleOffsetParameterActive](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/cycleoffsetparameteractive.md) | Define if the /cycle offset/ value is driven by an Animator controller parameter or by the value set in the editor.  |
| [iKOnFeet](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/ikonfeet.md)                                     | Should Foot IK be respected for this state.                                                                          |
| [mirror](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/mirror.md)                                         | Whether the animation state is mirrored.                                                                             |
| [mirrorParameter](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/mirrorparameter.md)                       | The animator controller parameter that drives the mirror value.                                                      |
| [mirrorParameterActive](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/mirrorparameteractive.md)           | Define if the `mirror` value is driven by an Animator controller parameter or by the value set in the editor.        |
| [motion](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/motion.md)                                         | The motion assigned to this state.                                                                                   |
| [nameHash](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/namehash.md)                                     | The hashed name of the state.                                                                                        |
| [speed](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/speed.md)                                           | The default speed of the motion.                                                                                     |
| [speedParameter](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/speedparameter.md)                         | The animator controller parameter that drives the speed value.                                                       |
| [speedParameterActive](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/speedparameteractive.md)             | Define if the `speed` value is driven by an Animator controller parameter or by the value set in the editor.         |
| [tag](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/tag.md)                                               | A tag can be used to identify a state.                                                                               |
| [timeParameter](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/timeparameter.md)                           | If timeParameterActive is true, the value of this Parameter will be used instead of normalized time.                 |
| [timeParameterActive](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/timeparameteractive.md)               | If true, use value of given Parameter as normalized time.                                                            |
| [transitions](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/transitions.md)                               | The transitions that are going out of the state.                                                                     |
| [writeDefaultValues](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/writedefaultvalues.md)                 | Whether or not the AnimatorStates writes back the default values for properties that are not animated by its Motion. |

## Methods

| Method                                                                                                                       | Description                                                                                     |
| ---------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| [AddExitTransition](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/addexittransition.md)               | Utility function to add an outgoing transition to the exit of the state's parent state machine. |
| [AddStateMachineBehaviour](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/addstatemachinebehaviour.md) | Non-generic version of this method.                                                             |
| [AddTransition](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/addtransition.md)                       | Utility function to add an outgoing transition to the destination state.                        |
| [RemoveTransition](/engine/6000.6/script-reference/unityeditor/animations/animatorstate/removetransition.md)                 | Utility function to remove a transition from the state.                                         |

## Inheritance

**Inherited Members:**

* [Object.GetEntityId()](/engine/6000.6/script-reference/unityengine/object/getentityid.md)
* [Object.GetHashCode()](/engine/6000.6/script-reference/unityengine/object/gethashcode.md)
* [Object.InstantiateAsync\<T>(T)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Transform)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Vector3, Quaternion)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Transform, Vector3, Quaternion)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Vector3, Quaternion)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, Vector3, Quaternion)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>, CancellationToken)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, InstantiateParameters, CancellationToken)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, InstantiateParameters, CancellationToken)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Vector3, Quaternion, InstantiateParameters, CancellationToken)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Vector3, Quaternion, InstantiateParameters, CancellationToken)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>, InstantiateParameters, CancellationToken)](/engine/6000.6/script-reference/unityengine/object/instantiateasync.md)
* [Object.Instantiate(Object, Vector3, Quaternion)](/engine/6000.6/script-reference/unityengine/object/instantiate.md#instantiate\(object-vector3-quaternion\))
* [Object.Instantiate(Object, Vector3, Quaternion, Transform)](/engine/6000.6/script-reference/unityengine/object/instantiate.md#instantiate\(object-vector3-quaternion-transform\))
* [Object.Instantiate(Object)](/engine/6000.6/script-reference/unityengine/object/instantiate.md#instantiate\(object\))
* [Object.Instantiate(Object, Scene)](/engine/6000.6/script-reference/unityengine/object/instantiate.md#instantiate\(object-scene\))
* [Object.Instantiate\<T>(T, InstantiateParameters)](/engine/6000.6/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion, InstantiateParameters)](/engine/6000.6/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate(Object, Transform)](/engine/6000.6/script-reference/unityengine/object/instantiate.md#instantiate\(object-transform\))
* [Object.Instantiate(Object, Transform, bool)](/engine/6000.6/script-reference/unityengine/object/instantiate.md#instantiate\(object-transform-bool\))
* [Object.Instantiate\<T>(T)](/engine/6000.6/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion)](/engine/6000.6/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion, Transform)](/engine/6000.6/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Transform)](/engine/6000.6/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Transform, bool)](/engine/6000.6/script-reference/unityengine/object/instantiate.md)
* [Object.Destroy(Object, float)](/engine/6000.6/script-reference/unityengine/object/destroy.md)
* [Object.DestroyImmediate(Object, bool)](/engine/6000.6/script-reference/unityengine/object/destroyimmediate.md)
* [Object.FindObjectsByType(Type)](/engine/6000.6/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytype\(type\))
* [Object.FindObjectsByType(Type, FindObjectsInactive)](/engine/6000.6/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytype\(type-findobjectsinactive\))
* [Object.DontDestroyOnLoad(Object)](/engine/6000.6/script-reference/unityengine/object/dontdestroyonload.md)
* [Object.FindAnyObjectByType\<T>()](/engine/6000.6/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytypet\(\))
* [Object.FindAnyObjectByType\<T>(FindObjectsInactive)](/engine/6000.6/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytypet\(findobjectsinactive\))
* [Object.FindObjectsByType\<T>()](/engine/6000.6/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytypet\(\))
* [Object.FindObjectsByType\<T>(FindObjectsInactive)](/engine/6000.6/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytypet\(findobjectsinactive\))
* [Object.FindAnyObjectByType(Type)](/engine/6000.6/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytype\(type\))
* [Object.FindAnyObjectByType(Type, FindObjectsInactive)](/engine/6000.6/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytype\(type-findobjectsinactive\))
* [Object.ToString()](/engine/6000.6/script-reference/unityengine/object/tostring.md)
* [Object.name](/engine/6000.6/script-reference/unityengine/object/name.md)
* [Object.hideFlags](/engine/6000.6/script-reference/unityengine/object/hideflags.md)

### Operators

| Operator                                                                           | Description                                                             |
| ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [operator ==](/engine/6000.6/script-reference/unityengine/object/op-equality.md)   | Compares two object references to see if they refer to the same object. |
| [bool](/engine/6000.6/script-reference/unityengine/object/op-implicit.md)          | Determines whether the object exists.                                   |
| [operator !=](/engine/6000.6/script-reference/unityengine/object/op-inequality.md) | Compares if two objects refer to a different object.                    |
