Motion
Stores a reference to an animation asset associated with a State Machine state.
Read time 4 minutesLast updated 5 days ago
Definition
- Type: Class
- Namespace: UnityEngine
- Assembly: UnityEngine.AnimationModule
- Inherits from: Object
public class Motion : Object
Remarks
The Motion class acts as an abstraction for APIs that accept either the AnimationClip or BlendTree animation classes.
This example demonstrates how to create a BlendTree from a selection of AnimationClips. This example also demonstrates how a BlendTree is composed of two or more child Motions, and how to use a BlendTree to instantiate an AnimatorState.
Examples
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
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |