ExitEvent Class

Summary

[Pro-Only] A callback for when an Animancer.AnimancerNode.EffectiveWeight becomes 0.
Assembly
Animancer.dll
Namespace
Animancer
Interfaces
Base Types
graph BT Type-->Base0["Key"] click Base0 "/animancer-v7-4/api/Animancer/Key" Base0-->Base1["Object"] Type-.->Interface0["IUpdatable"] click Interface0 "/animancer-v7-4/api/Animancer/IUpdatable" Type-.->Interface1["Key.IListItem"] click Interface1 "/animancer-v7-4/api/Animancer/IListItem" Type["ExitEvent"] class Type type-node

Syntax

public class ExitEvent : Key, IUpdatable, Key.IListItem

Examples

[SerializeField] private AnimancerComponent _Animancer;
[SerializeField] private AnimationClip _Clip;

private void Awake()
{
    // Play the animation.
    var state = _Animancer.Play(_Clip);
    
    // Then give its state an exit event.
    ExitEvent.Register(state, () => Debug.Log("State Exited"));
    
    // That event will never actually get triggered because we are never playing anything else.
}
Unlike Animancer Events, an Animancer.ExitEvent will not be cleared automatically when you play something (because that's the whole point) so if you are playing the same animation repeatedly you will need to check its Animancer.AnimancerNode.EffectiveWeight before registering the event (otherwise all the callbacks you register will stay active).

private void Update()
{
    // Only register the exit event if the state was at 0 weight before.
    var state = _Animancer.GetOrCreate(_Clip);
    if (state.EffectiveWeight == 0)
        ExitEvent.Register(state, () => Debug.Log("State Exited"));
        
    // Then play the state normally.
    _Animancer.Play(state);
    // _Animancer.Play(_Clip); would work too, but we already have the state so using it directly is faster.
}

Remarks

Most Finite State Machine systems already have their own mechanism for notifying your code when a state is exited so this system is generally only useful when something like that is not already available.

Fields

Name Constant Value Summary
NotInList -1
The Animancer.Key._Index which indicates that an item isn't in a list.
Inherited from Key
static

Methods

Name Value Summary
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
IsInList(Key) bool
Is the `key` currently in a keyed list?
Inherited from Key
static
Register(AnimancerNode, Action) void
Registers the `callback` to be triggered when the Animancer.AnimancerNode.EffectiveWeight becomes 0.
static
Unregister(AnimancerNode) bool
Removes a registered Animancer.ExitEvent targeting the specified `node` and returns true if there was one.
static
Unregister(AnimancerPlayable) bool
Removes a registered Animancer.ExitEvent and returns true if there was one.
static