Version: 2021.3
LanguageEnglish
  • C#

Animation

class in UnityEngine

/

Inherits from:Behaviour

/

Implemented in:UnityEngine.AnimationModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

The animation component is used to play back animations.

You can assign animation clips to the animation component and control playback from your script. The animation system in Unity is weight-based and supports Animation Blending, Additive animations, Animation Mixing, Layers and full control over all aspects of playback.

For an overview of animation scripting in Unity please read this introduction.

AnimationState can be used to change the layer of an animation, modify playback speed, and for direct control over blending and mixing.

Also Animation supports enumerators. Looping through all AnimationStates is performed like this:

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Animation anim;

void Start() { anim = GetComponent<Animation>(); foreach (AnimationState state in anim) { state.speed = 0.5F; } } }

Additional resources: An overview of animation scripting in Unity is here.

Properties

animatePhysicsWhen turned on, animations will be executed in the physics loop. This is only useful in conjunction with kinematic rigidbodies.
clipThe default animation.
cullingTypeControls culling of this Animation component.
isPlayingIs an animation currently being played?
localBoundsAABB of this Animation animation component in local space.
playAutomaticallyShould the default animation clip (the Animation.clip property) automatically start playing on startup?
this[string]Returns the animation state named name.
wrapModeHow should time beyond the playback range of the clip be treated?

Public Methods

AddClipAdds a clip to the animation with name newName.
BlendBlends the animation named animation towards targetWeight over the next time seconds.
CrossFadeFades in the animation with the name animation over a period of time defined by fadeLength.
CrossFadeQueuedCross fades an animation after previous animations has finished playing.
GetClipCountGet the number of clips currently assigned to this animation.
IsPlayingIs the animation named name playing?
PlayPlays an animation without blending.
PlayQueuedPlays an animation after previous animations has finished playing.
RemoveClipRemove clip from the animation list.
RewindRewinds the animation named name.
SampleSamples animations at the current state.
StopStops all playing animations that were started with this Animation.

Inherited Members

Properties

enabledEnabled Behaviours are Updated, disabled Behaviours are not.
isActiveAndEnabledReports whether a GameObject and its associated Behaviour is active and enabled.
gameObjectThe game object this component is attached to. A component is always attached to a game object.
tagThe tag of this game object.
transformThe Transform attached to this GameObject.
hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameThe name of the object.

Public Methods

BroadcastMessageCalls the method named methodName on every MonoBehaviour in this game object or any of its children.
CompareTagChecks the GameObject's tag against the defined tag.
GetComponentGets a reference to a component of type T on the same GameObject as the component specified.
GetComponentInChildrenGets a reference to a component of type T on the same GameObject as the component specified, or any child of the GameObject.
GetComponentInParentGets a reference to a component of type T on the same GameObject as the component specified, or any parent of the GameObject.
GetComponentsGets references to all components of type T on the same GameObject as the component specified.
GetComponentsInChildrenGets references to all components of type T on the same GameObject as the component specified, and any child of the GameObject.
GetComponentsInParentGets references to all components of type T on the same GameObject as the component specified, and any parent of the GameObject.
SendMessageCalls the method named methodName on every MonoBehaviour in this game object.
SendMessageUpwardsCalls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.
TryGetComponentGets the component of the specified type, if it exists.
GetInstanceIDGets the instance ID of the object.
ToStringReturns the name of the object.

Static Methods

DestroyRemoves a GameObject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
FindObjectsOfTypeGets a list of all loaded objects of Type type.
InstantiateClones the object original and returns the clone.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.