Animancer v6.0 is currently available for testing.

AnimationEventReceiver Struct

Summary

A callback to be invoked by Animation Events that have been triggered by a specific animation.
Assembly
Animancer.dll
Namespace
Animancer
Base Types
  • ValueType
graph BT Type-->Base0["ValueType"] Type["AnimationEventReceiver"] class Type type-node

Syntax

public struct AnimationEventReceiver : ValueType

Examples

To set up a receiver for an Animation Event with the Function Name "Event":

/// <summary>A callback for Animation Events with the Function Name "Event".</summary>
public AnimationEventReceiver onEvent;

/// <summary>Called by Animation Events.</summary>
private void Event(AnimationEvent animationEvent)
{
    // This is optional and will automatically be compiled out of runtime builds.
    // It allows the receiver to perform additional safety checks.
    onEvent.SetFunctionName("Event");
    
    onEvent.HandleEvent(animationEvent);
}
Then to register a callback to that receiver:

var state = animancer.Play(clip);
onEvent.Set(state, (animationEvent) =>
{
    ...
});

Remarks

Documentation: Animation Events

Constructors

Name Summary
AnimationEventReceiver(AnimancerState, Action<AnimationEvent>) Creates a new Animancer.AnimationEventReceiver and sets the Animancer.AnimationEventReceiver.Source and Animancer.AnimationEventReceiver.Callback.

Properties

Name Value Summary
Callback Action<AnimationEvent>
A delegate that will be invoked by Animancer.AnimationEventReceiver.HandleEvent(UnityEngine.AnimationEvent).

It is recommended that you use Animancer.AnimationEventReceiver.Set(Animancer.AnimancerState,System.Action{UnityEngine.AnimationEvent}) or manually specify a Animancer.AnimationEventReceiver.Source when assigning this reference. Otherwise events from an animation that is fading out might trigger a callback you just registered for a new animation that is fading in.
FunctionName string
[Editor-Only] The function name of the event that this receiver is intended for.
Source AnimancerState
If set, only Animation Events caused by this state before the Animancer.AnimancerLayer.CommandCount changes will actually trigger the Animancer.AnimationEventReceiver.Callback.

Methods

Name Value Summary
Clear() void
Clears the Animancer.AnimationEventReceiver.Source and Animancer.AnimationEventReceiver.Callback.
HandleEvent(AnimationEvent) bool
Invokes the Animancer.AnimationEventReceiver.Callback if either no Animancer.AnimationEventReceiver.Source has been set or if it is still current and its Animancer.AnimancerState.Clip matches the one triggering the event.
Set(AnimancerState, Action<AnimationEvent>) void
Sets the Animancer.AnimationEventReceiver.Source and Animancer.AnimationEventReceiver.Callback.
SetFunctionName(string) void
[Editor-Conditional] Sets the Animancer.AnimationEventReceiver.FunctionName so Animancer.AnimationEventReceiver.Set(Animancer.AnimancerState,System.Action{UnityEngine.AnimationEvent}) can perform additional safety checks to ensure that the Animancer.AnimancerState.Clip actually has an event with the expected `name` and also to allow Animancer.AnimationEventReceiver.HandleEvent(UnityEngine.AnimationEvent) to verify that any events it is given have that `name` as well.