AnimancerLayer Class

Summary

A layer on which animations can play with their states managed independantly of other layers while blending the output with those layers.

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
graph BT Type-->Base0["AnimancerNode"] click Base0 "/animancer/api/Animancer/AnimancerNode" Base0-->Base1["Key"] click Base1 "/animancer/api/Animancer/Key" Base1-->Base2["Object"] Type-.->Interface0["IKeyHolder"] click Interface0 "/animancer/api/Animancer/IKeyHolder" Type-.->Interface1["IEnumerable<AnimancerState>"] Type-.->Interface2["IEnumerator"] Type-.->Interface3["IPlayableWrapper"] click Interface3 "/animancer/api/Animancer/IPlayableWrapper" Type-.->Interface4["IAnimationClipCollection"] click Interface4 "/animancer/api/Animancer/IAnimationClipCollection" Type["AnimancerLayer"] class Type type-node

Syntax

public sealed class AnimancerLayer : AnimancerNode, IKeyHolder, IEnumerable<AnimancerState>, 
    IEnumerator, IPlayableWrapper, IAnimationClipCollection

Fields

Name Constant Value Summary
maxStateDepth
[Editor-Only] The maximum number of duplicate states that can be created by Animancer.AnimancerLayer.GetOrCreateWeightlessState(Animancer.AnimancerState) for a single clip before it will start giving usage warnings. Default = 5.
static
Root
The Animancer.AnimancerPlayable at the root of the graph.
Inherited from AnimancerNode

Properties

Name Value Summary
ApplyAnimatorIK bool
Determines whether OnAnimatorIK(int layerIndex) will be called on the animated object for any Animancer.AnimancerLayer.States. The initial value is determined by Animancer.AnimancerLayer.DefaultApplyAnimatorIK when a new state is created and setting this value will also set the default.

This is equivalent to the "IK Pass" toggle in Animator Controller layers, except that due to limitations in the Playables API the layerIndex will always be zero.

It requires Unity 2018.1 or newer, however 2018.3 or newer is recommended because a bug in earlier versions of the Playables API caused this value to only take effect while at least one state was at Animancer.AnimancerNode.Weight = 1 which meant that IK would not work while fading between animations.
ApplyFootIK bool
Determines whether any of the Animancer.AnimancerLayer.States in this layer are applying IK to the character's feet. The initial value is determined by Animancer.AnimancerLayer.DefaultApplyFootIK when a new state is created.

This is equivalent to the "Foot IK" toggle in Animator Controller states (applied to the whole layer).
AverageVelocity Vector3
The average velocity of the root motion of all currently playing animations, taking their current Animancer.AnimancerNode.Weight into account.
ChildCount int
The number of states using this layer as their Animancer.AnimancerState.Parent.
CommandCount int
The number of times the Animancer.AnimancerLayer.CurrentState has changed. By storing this value and later comparing the stored value to the current value, you can determine whether the state has been changed since then, even it has changed back to the same state.
CurrentState AnimancerState
The state of the animation currently being played.

Specifically, this is the state that was most recently started using any of the Play or CrossFade methods on this layer. States controlled individually via methods in the Animancer.AnimancerState itself will not register in this property.

Each time this property changes, the Animancer.AnimancerLayer.CommandCount is incremented.
DefaultApplyAnimatorIK bool
Determines the default value of Animancer.AnimancerState.ApplyAnimatorIK for all new states created in this layer. Default false.

It requires Unity 2018.1 or newer, however 2018.3 or newer is recommended because a bug in earlier versions of the Playables API caused this value to only take effect while at least one state was at Animancer.AnimancerNode.Weight = 1 which meant that IK would not work while fading between animations.
DefaultApplyFootIK bool
Determines the default value of Animancer.AnimancerState.ApplyFootIK for all new states created in this layer. Default false.
EffectiveSpeed float
The Animancer.AnimancerNode.Speed of this node multiplied by the Animancer.AnimancerNode.Speed of each of its parents down the hierarchy (including the root Animancer.AnimancerPlayable) to determine the actual speed its output is being played at.
Inherited from AnimancerNode
FadeSpeed float
The speed at which this node is fading towards the Animancer.AnimancerNode.TargetWeight.
Inherited from AnimancerNode
Index int
The index of the port this node is connected to on the parent's UnityEngine.Playables.Playable.

A negative value indicates that it is not assigned to a port.
Inherited from AnimancerNode
IsAdditive bool
[Pro-Only] Determines whether this layer is set to additive blending. Otherwise it will override any earlier layers.
IsValid bool
Indicates whether the Animancer.AnimancerNode._Playable is usable (properly initialised and not destroyed).
Inherited from AnimancerNode
KeepChildrenConnected bool
Indicates whether child playables should stay connected to this mixer at all times.
Layer AnimancerLayer
A layer is its own root.
Parent IPlayableWrapper
The Animancer.AnimancerNode.Root receives the output of the UnityEngine.Playables.Playable.
Speed float
How fast the Animancer.AnimancerState.Time is advancing every frame.

1 is the normal speed.

A negative value will play the animation backwards.

Animancer Lite does not allow this value to be changed in a runtime build.
Inherited from AnimancerNode
TargetWeight float
The desired Animancer.AnimancerNode.Weight which this node is fading towards according to the Animancer.AnimancerNode.FadeSpeed.
Inherited from AnimancerNode
this[int] AnimancerState
Returns the state connected to the specified `index` as a child of this layer.
Weight float
The current blend weight of this node which determines how much it affects the final output. 0 has no effect while 1 applies the full effect of this node and values inbetween apply a proportional effect.

Setting this property cancels any fade currently in progress. If you don't wish to do that, you can use Animancer.AnimancerNode.SetWeight(System.Single) instead.

Animancer Lite only allows this value to be set to 0 or 1 in a runtime build.
Inherited from AnimancerNode

Methods

Name Value Summary
AddChild(AnimancerState) void
Adds a new port and uses Animancer.AnimancerState.SetParent(Animancer.AnimancerNode,System.Int32) to connect the `state` to it.
AppendDescription(StringBuilder, int, string) void
Appends a detailed descrption of the current details of this node.
Inherited from AnimancerNode
AppendDetails(StringBuilder, string) void
Called by Animancer.AnimancerNode.AppendDescription(System.Text.StringBuilder,System.Int32,System.String) to append the details of this node.
ConnectToGraph() void
Connects the Animancer.AnimancerNode._Playable to the Animancer.AnimancerNode.Parent.
Inherited from AnimancerNode
CreateIfNew(AnimationClip, AnimationClip) void
Calls Animancer.AnimancerLayer.GetOrCreateState(UnityEngine.AnimationClip,System.Boolean) for each of the specified clips.

If you only want to create a single state, use Animancer.AnimancerLayer.CreateState(UnityEngine.AnimationClip).
CreateIfNew(AnimationClip, AnimationClip, AnimationClip) void
Calls Animancer.AnimancerLayer.GetOrCreateState(UnityEngine.AnimationClip,System.Boolean) for each of the specified clips.

If you only want to create a single state, use Animancer.AnimancerLayer.CreateState(UnityEngine.AnimationClip).
CreateIfNew(AnimationClip, AnimationClip, AnimationClip, AnimationClip) void
Calls Animancer.AnimancerLayer.GetOrCreateState(UnityEngine.AnimationClip,System.Boolean) for each of the specified clips.

If you only want to create a single state, use Animancer.AnimancerLayer.CreateState(UnityEngine.AnimationClip).
CreateIfNew(AnimationClip[]) void
Calls Animancer.AnimancerLayer.GetOrCreateState(UnityEngine.AnimationClip,System.Boolean) for each of the specified clips.

If you only want to create a single state, use Animancer.AnimancerLayer.CreateState(UnityEngine.AnimationClip).
CreateState(AnimationClip) ClipState
Creates and returns a new Animancer.ClipState to play the `clip`.

This method uses Animancer.AnimancerPlayable.GetKey(UnityEngine.AnimationClip) to determine the Animancer.AnimancerState.Key.
CreateState(Object, AnimationClip) ClipState
Creates and returns a new Animancer.ClipState to play the `clip` and registers it with the `key`.
DestroyStates() void
Destroys all states connected to this layer. This operation cannot be undone.
DisconnectFromGraph() void
Disconnects the Animancer.AnimancerNode._Playable from the Animancer.AnimancerNode.Parent.
Inherited from AnimancerNode
GatherAnimationClips(ICollection<AnimationClip>) void
[Animancer.IAnimationClipCollection] Gathers all the animations in this layer.
GetChild(int) AnimancerState
Returns the state connected to the specified `index` as a child of this layer.
GetDescription(int, string) string
Returns a detailed descrption of the current details of this node.
Inherited from AnimancerNode
GetEnumerator() IEnumerator<AnimancerState>
Returns an enumerator that will iterate through all states connected directly to this layer (not inside Animancer.MixerStates).
GetOrCreateState(AnimationClip, bool) AnimancerState
Calls Animancer.AnimancerPlayable.GetKey(UnityEngine.AnimationClip) and returns the state which registered with that key or creates one if it doesn't exist.

If the state already exists but has the wrong Animancer.AnimancerState.Clip, the `allowSetClip` parameter determines what will happen. False causes it to throw an System.ArgumentException while true allows it to change the Animancer.AnimancerState.Clip. Note that the change is somewhat costly to performance to use with caution.
GetOrCreateState(ITransition) AnimancerState
Returns the state registered with the Animancer.IHasKey.Key if there is one. Otherwise this method uses Animancer.ITransition.CreateState(Animancer.AnimancerLayer) to create a new one and registers it with that key before returning it.
GetOrCreateState(Object, AnimationClip, bool) AnimancerState
Returns the state which registered with the `key` or creates one if it doesn't exist.

If the state already exists but has the wrong Animancer.AnimancerState.Clip, the `allowSetClip` parameter determines what will happen. False causes it to throw an System.ArgumentException while true allows it to change the Animancer.AnimancerState.Clip. Note that the change is somewhat costly to performance to use with caution.
GetOrCreateWeightlessState(AnimancerState) AnimancerState
If the `state` is not currently at 0 Animancer.AnimancerNode.Weight, this method finds a copy of it which is at 0 or creates a new one.
GetTotalWeight() float
Calculates the total Animancer.AnimancerNode.Weight of all states in this layer.
IndexOf(Key) int
Returns location of this object in the list (or -1 if it is not currently in a keyed list).
Inherited from Key
static
IsAnyStatePlaying() bool
Returns true if at least one animation is being played.
IsInList(Key) bool
Indicates whether the specified object is currently in a keyed list.
Inherited from Key
static
IsPlayingClip(AnimationClip) bool
Returns true if the `clip` is currently being played by at least one state.
OnAddChild(IList<AnimancerState>, AnimancerState) void
Connects the `state` to the `mixer` at its Animancer.AnimancerNode.Index.
Inherited from AnimancerNode
Play(AnimancerState) AnimancerState
Stops all other animations, plays the `state`, and returns it.

The animation will continue playing from its current Animancer.AnimancerState.Time. If you wish to force it back to the start, you can simply set the `state`s time to 0.
Play(AnimancerState, float, FadeMode) AnimancerState
Starts fading in the `state` over the course of the `fadeDuration` while fading out all others in this 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 Animancer.AnimancerState.Play 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).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 Animancer.AnimancerState.Play the `state`.

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.AnimancerLayer.Play(Animancer.AnimancerState) or Animancer.AnimancerLayer.Play(Animancer.AnimancerState,System.Single,Animancer.FadeMode) depending on the Animancer.ITransition.FadeDuration.
Play(ITransition, float, FadeMode) AnimancerState
Creates a state for the `transition` if it didn't already exist, then calls Animancer.AnimancerLayer.Play(Animancer.AnimancerState) or Animancer.AnimancerLayer.Play(Animancer.AnimancerState,System.Single,Animancer.FadeMode) depending on the Animancer.ITransition.FadeDuration.
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. If you wish to force it back to the start, you can simply set the returned state's time to 0. on the returned state.
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 Animancer.AnimancerState.Play the `state`.

Animancer Lite only allows the default `fadeDuration` (0.25 seconds) in a runtime build.
SetMask(AvatarMask) void
[Pro-Only] Sets an UnityEngine.AvatarMask to determine which bones this layer will affect.
SetName(string) void
[Editor-Conditional] Sets the Inspector display name of this layer. Note that layer names are Editor-Only so any calls to this method will automatically be compiled out of a runtime build.
SetWeight(float) void
Sets the current blend weight of this node which determines how much it affects the final output. 0 has no effect while 1 applies the full effect of this node.

This method allows any fade currently in progress to continue. If you don't wish to do that, you can set the Animancer.AnimancerNode.Weight property instead.

Animancer Lite only allows this value to be set to 0 or 1 in a runtime build.
Inherited from AnimancerNode
StartFade(float, float) void
Calls Animancer.AnimancerNode.OnStartFade and starts fading the Animancer.AnimancerNode.Weight over the course of the `fadeDuration` (in seconds).

If the `targetWeight` is 0 then Animancer.AnimancerNode.Stop will be called when the fade is complete.

If the Animancer.AnimancerNode.Weight is already equal to the `targetWeight` then the fade will end immediately.

Animancer Lite only allows a `targetWeight` of 0 or 1 and the default `fadeDuration` in a runtime build.
Inherited from AnimancerNode
Stop() void
Sets Animancer.AnimancerNode.Weight = 0 and calls Animancer.AnimancerState.Stop on all animations to stop them from playing and rewind them to the start.
ToString() string
The Inspector display name of this layer.

Extension Methods

Name Value Summary
CalculateEditorFadeDuration(float) float
Returns the duration of the `node`s current fade (if any), otherwise returns the `defaultDuration`.
IsValid() bool
Returns true if the `node` is not null and Animancer.AnimancerNode.IsValid.