# Motion

> Stores a reference to an animation asset associated with a State Machine state.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine](/engine/6000.5/script-reference/unityengine.md)
* **Assembly:** UnityEngine.AnimationModule
* **Inherits from:** [Object](/engine/6000.5/script-reference/unityengine/object.md)

```csharp
public class Motion : Object
```

## Remarks

The [Motion](/engine/6000.5/script-reference/unityengine/motion.md) class acts as an abstraction for APIs that accept either the [AnimationClip](/engine/6000.5/script-reference/unityengine/animationclip.md) or [BlendTree](/engine/6000.5/script-reference/unityeditor/animations/blendtree.md) animation classes.

Additional Resources: [AnimatorState.motion](/engine/6000.5/script-reference/unityeditor/animations/animatorstate/motion.md), [AnimatorController.AddMotion](/engine/6000.5/script-reference/unityeditor/animations/animatorcontroller/addmotion.md), [BlendTree.AddChild](/engine/6000.5/script-reference/unityeditor/animations/blendtree/addchild.md).

This example demonstrates how to create a [BlendTree](/engine/6000.5/script-reference/unityeditor/animations/blendtree.md) from a selection of [AnimationClips](/engine/6000.5/script-reference/unityengine/animationclip.md). This example also demonstrates how a [BlendTree](/engine/6000.5/script-reference/unityeditor/animations/blendtree.md) is composed of two or more child [Motion](/engine/6000.5/script-reference/unityengine/motion.md)s, and how to use a [BlendTree](/engine/6000.5/script-reference/unityeditor/animations/blendtree.md) to instantiate an [AnimatorState](/engine/6000.5/script-reference/unityeditor/animations/animatorstate.md).

## Examples

```csharp
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;

static class MotionClassExample
{
    [MenuItem("Example/Create Animator Controller From Selected Clips")]
    static void CreateAnimatorControllerFromClips()
    {
        // Get the Motion-derived assets in the selection. You can only do this with AnimationClip assets.
        var motions = new List<Motion>();
        foreach (var obj in Selection.objects)
        {
            if (obj is Motion clip)
            {
                motions.Add(clip);
            }
        }

        if (motions.Count == 0)
        {
            Debug.LogWarning("No clips selected");
            return;
        }

        // Create an AnimationController in the project.
        var animatorController =
            AnimatorController.CreateAnimatorControllerAtPath(
                AssetDatabase.GenerateUniqueAssetPath("Assets/MotionExample.controller"));

        // Create a BlendTree that blends between the selected Motion objects.
        var blendTree = new BlendTree { name = "Default" };
        for (var i = 0; i < motions.Count; i++)
        {
            var clip = motions[i];
            blendTree.AddChild(clip, (float)i / motions.Count);
        }

        // Create a new state from the BlendTree (which is itself a Motion).
        animatorController.AddMotion(blendTree);

        // Make sure the BlendTree is persisted.
        AssetDatabase.AddObjectToAsset(blendTree, animatorController);

        // Show the new  AnimatorController in the project window.
        Selection.activeObject = animatorController;
        EditorGUIUtility.PingObject(animatorController);
    }
}
```

## Inheritance

**Inherited Members:**

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

### Operators

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