Legacy Documentation: Version 2018.2 (Go to current version)
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; } } }

See Also: 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 the animation with name animation in over a period of time seconds and fades other animations out.
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.
isActiveAndEnabledHas the Behaviour had enabled called.
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.
CompareTagIs this game object tagged with tag ?
GetComponentReturns the component of Type type if the game object has one attached, null if it doesn't.
GetComponentInChildrenReturns the component of Type type in the GameObject or any of its children using depth first search.
GetComponentInParentReturns the component of Type type in the GameObject or any of its parents.
GetComponentsReturns all components of Type type in the GameObject.
GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children.
GetComponentsInParentReturns all components of Type type in the GameObject or any of its parents.
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.
GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the GameObject.

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.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeReturns a list of all active 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.

Did you find this page useful? Please give it a rating: