AnimancerComponent Class

Summary

The main component through which other scripts can interact with Animancer. It allows you to play animations on an UnityEngine.Animator without using a UnityEngine.RuntimeAnimatorController.

This class can be used as a custom yield instruction to wait until all animations finish playing.
Assembly
Animancer.dll
Namespace
Animancer
Interfaces
Base Types
  • MonoBehaviour
Derived Types
graph BT Type-->Base0["MonoBehaviour"] Type-.->Interface0["IAnimancerComponent"] click Interface0 "/animancer/api/Animancer/IAnimancerComponent" Type-.->Interface1["IEnumerable<AnimancerState>"] Type-.->Interface2["IEnumerator"] Type-.->Interface3["IAnimationClipSource"] click Interface3 "/animancer/api/Animancer/IAnimationClipSource" Type-.->Interface4["IAnimationClipSource"] Type-.->Interface5["IAnimationClipCollection"] click Interface5 "/animancer/api/Animancer/IAnimationClipCollection" Type["AnimancerComponent"] class Type type-node Derived0["NamedAnimancerComponent"]-->Type click Derived0 "/animancer/api/Animancer/NamedAnimancerComponent"

Syntax

[AddComponentMenu(Strings.MenuPrefix + "Animancer Component")]
[HelpURL(Strings.APIDocumentationURL + "/AnimancerComponent")]
[DefaultExecutionOrder(-5000)]
public class AnimancerComponent : MonoBehaviour, IAnimancerComponent, IEnumerable<AnimancerState>, 
    IEnumerator, IAnimationClipSource, IAnimationClipSource, IAnimationClipCollection

Remarks

This class is mostly just a wrapper that connects an Animancer.AnimancerPlayable to an UnityEngine.Animator.

Attributes

Type Description
AddComponentMenu
HelpURLAttribute
DefaultExecutionOrder

Properties

Name Value Summary
ActionOnDisable AnimancerComponent.DisableAction
[UnityEngine.SerializeField] Determines what happens when this component is disabled or its UnityEngine.GameObject becomes inactive (i.e. in Animancer.AnimancerComponent.OnDisable).

The default value is Animancer.AnimancerComponent.DisableAction.Stop.
Animator Animator
[UnityEngine.SerializeField] The UnityEngine.Animator component which this script controls.
InitialUpdateMode Nullable<AnimatorUpdateMode>
[Editor-Only] The Animancer.AnimancerComponent.UpdateMode what was first used when this script initialised. This is used to give a warning when changing to or from UnityEngine.AnimatorUpdateMode.AnimatePhysics at runtime since it won't work correctly.
IsPlayableInitialised bool
Indicates whether the Animancer.AnimancerComponent.Playable has been initialised.
Layers AnimancerPlayable.LayerList
The layers which each manage their own set of animations.
Playable AnimancerPlayable
The internal system which manages the playing animations. Accessing this property will automatically initialise it.
States AnimancerPlayable.StateDictionary
The states managed by this component.
UpdateMode AnimatorUpdateMode
Determines when animations are updated and which time source is used. This property is mainly a wrapper around the UnityEngine.Animator.updateMode.

Note that changing to or from UnityEngine.AnimatorUpdateMode.AnimatePhysics at runtime has no effect.

Methods

Name Value Summary
~AnimancerComponent() void
[Editor-Only] Ensures that the UnityEngine.Playables.PlayableGraph is destroyed.
Evaluate() void
Evaluates all of the currently playing animations to apply their states to the animated objects.
Evaluate(float) void
Advances all currently playing animations by the specified amount of time (in seconds) and evaluates the graph to apply their states to the animated objects.
GatherAnimationClips(ICollection<AnimationClip>) void
[Animancer.IAnimationClipCollection] Gathers all the animations in the Animancer.AnimancerComponent.Playable.

In the Unity Editor this method also gathers animations from other components on parent and child objects.
GetAnimationClips(List<AnimationClip>) void
[Animancer.IAnimationClipSource] Calls Animancer.AnimancerComponent.GatherAnimationClips(System.Collections.Generic.ICollection{UnityEngine.AnimationClip}).
GetEnumerator() IEnumerator<AnimancerState>
Returns an enumerator that will iterate through all states in each layer (not states inside mixers).
GetKey(AnimationClip) Object
Returns the `clip` itself. This method is used to determine the dictionary key to use for an animation when none is specified by the user, such as in Animancer.AnimancerComponent.Play(UnityEngine.AnimationClip). It can be overridden by child classes to use something else as the key.
InitialisePlayable() void
Creates a new Animancer.AnimancerPlayable if it doesn't already exist.
IsPlaying() bool
Returns true if at least one animation is being played.
IsPlaying(AnimancerState) bool
[Warning] You should not use an Animancer.AnimancerState as a key. Just check Animancer.AnimancerState.IsPlaying.
IsPlaying(AnimationClip) bool
Returns true if a state is registered for the `clip` and it is currently playing.

The actual dictionary key is determined using Animancer.AnimancerComponent.GetKey(UnityEngine.AnimationClip).
IsPlaying(IHasKey) bool
Returns true if a state is registered with the Animancer.IHasKey.Key and it is currently playing.
IsPlaying(Object) bool
Returns true if a state is registered with the `key` and it is currently playing.
IsPlayingClip(AnimationClip) bool
Returns true if the `clip` is currently being played by at least one state.

This method is inefficient because it searches through every state to find any that are playing the `clip`, unlike Animancer.AnimancerComponent.IsPlaying(UnityEngine.AnimationClip) which only checks the state registered using the `clip`s key.
OnDestroy() void
Called by Unity when this component is destroyed. Ensures that the Animancer.AnimancerComponent.Playable is properly cleaned up.
OnDisable() void
Called by Unity when this component becomes disabled or inactive. Acts according to the Animancer.AnimancerComponent.ActionOnDisable.
OnEnable() void
Called by Unity when this component becomes enabled and active.

Ensures that the UnityEngine.Playables.PlayableGraph is playing.
Play(AnimancerState) AnimancerState
Stops all other animations, plays the `state`, and returns it.

The animation will continue playing from its current Animancer.AnimancerState.Time. To restart it from the beginning you can use ...Play(state).Time = 0;.
Play(AnimancerState, float, FadeMode) AnimancerState
Starts fading in the `state` over the course of the `fadeDuration` while fading out all others in the same layer. Returns the `state`.

If the `state` was already playing and fading in with less time remaining than the `fadeDuration`, this method will allow it to complete the existing fade rather than starting a slower one.

If the layer currently has 0 Animancer.AnimancerNode.Weight, this method will fade in the layer itself and simply AnimancerState.Play(AnimancerState) the `state`.

Animancer Lite only allows the default `fadeDuration` (0.25 seconds) in a runtime build.
Play(AnimationClip) AnimancerState
Stops all other animations, plays the `clip`, and returns its state.

The animation will continue playing from its current Animancer.AnimancerState.Time. To restart it from the beginning you can use ...Play(clip, layerIndex).Time = 0;.
Play(AnimationClip, float, FadeMode) AnimancerState
Starts fading in the `clip` over the course of the `fadeDuration` while fading out all others in the same layer. Returns its state.

If the `state` was already playing and fading in with less time remaining than the `fadeDuration`, this method will allow it to complete the existing fade rather than starting a slower one.

If the layer currently has 0 Animancer.AnimancerNode.Weight, this method will fade in the layer itself and simply AnimancerState.Play(AnimationClip) the `clip`.

Animancer Lite only allows the default `fadeDuration` (0.25 seconds) in a runtime build.
Play(ITransition) AnimancerState
Creates a state for the `transition` if it didn't already exist, then calls Animancer.AnimancerComponent.Play(Animancer.AnimancerState) or Animancer.AnimancerComponent.Play(Animancer.AnimancerState,System.Single,Animancer.FadeMode) depending on ITransition.CrossFadeFromStart.
Play(ITransition, float, FadeMode) AnimancerState
Creates a state for the `transition` if it didn't already exist, then calls Animancer.AnimancerComponent.Play(Animancer.AnimancerState) or Animancer.AnimancerComponent.Play(Animancer.AnimancerState,System.Single,Animancer.FadeMode) depending on ITransition.CrossFadeFromStart.
Play(Object) AnimancerState
Stops all other animations, plays the animation registered with the `key`, and returns that state. If no state is registered with the `key`, this method does nothing and returns null.

The animation will continue playing from its current Animancer.AnimancerState.Time. To restart it from the beginning you can use ...Play(key).Time = 0;.
Play(Object, float, FadeMode) AnimancerState
Starts fading in the animation registered with the `key` over the course of the `fadeDuration` while fading out all others in the same layer. Returns the animation's state (or null if none was registered).

If the state was already playing and fading in with less time remaining than the `fadeDuration`, this method will allow it to complete the existing fade rather than starting a slower one.

If the layer currently has 0 Animancer.AnimancerNode.Weight, this method will fade in the layer itself and simply AnimancerState.Play(AnimancerState) the state.

Animancer Lite only allows the default `fadeDuration` (0.25 seconds) in a runtime build.
Reset() void
[Editor-Only] Called by the Unity Editor when this component is first added (in Edit Mode) and whenever the Reset command is executed from its context menu.

Destroys the playable if one has been initialised. Searches for an UnityEngine.Animator on this object, or it's children or parents. Removes the UnityEngine.Animator.runtimeAnimatorController if it finds one.

This method also prevents you from adding multiple copies of this component to a single object. Doing so will destroy the new one immediately and change the old one's type to match the new one, allowing you to change the type without losing the values of any serialized fields they share.
Stop() void
Stops all animations and rewinds them to the start.
Stop(AnimancerState) AnimancerState
[Warning] You should not use an Animancer.AnimancerState as a key. Just call Animancer.AnimancerState.Stop.
Stop(AnimationClip) AnimancerState
Gets the state associated with the `clip`, stops and rewinds it to the start, then returns it.
Stop(IHasKey) AnimancerState
Gets the state registered with the Animancer.IHasKey.Key, stops and rewinds it to the start, then returns it.
Stop(Object) AnimancerState
Gets the state associated with the `key`, stops and rewinds it to the start, then returns it.

Operators

Name Value Summary
implicit operator AnimancerLayer(AnimancerComponent) AnimancerLayer