Animancer v6.0 is currently available for testing.

Animation Events

Unity's inbuilt Animation Event system works the same when using Animancer as without it. The Unity Manual explains how to set up events using the Animation Tab of a model's import settings or the Animation Window. To receive the events, you simply attach a script to the same object as the Animator component and the engine will look for a method in that script with whatever Function name the event specifies. The Animation Events examples demonstrate how to use them.

It can be convenient to have your event listener script Interit from AnimancerComponent for organisational purposes (instead of having two separate components), but most events do not actually have any direct interaction with Animancer.

Note that any event with a string or AnimationEvent parameter will allocate some Garbage every time it is triggered, which can potentially cause performance issues.

Simple Events

The SimpleEventReceiver component has an OnEvent callback which is triggered by Animation Events using the Function name "Event". This means you can start an animation then register a callback for when its event occurs. It will automatically assert that the AnimationClip actually has an event with that name (while in the Unity Editor).

The SimpleEventReceiver component mainly serves as an example of how you can implement your own events using the AnimationEventReceiver struct, but it could be useful in a simple game if you set up all of your animations with only one event each that uses "Event" as the Function name (Attack script uses the event to indicate the hit time, Walk script uses it to play footstep sounds, etc). The callback takes the triggering AnimationEvent as a parameter so you can access any of its values, including the AnimationClip that it comes from.

Using simple events in code is similar to using End Events, you simply access OnEvent on the SimpleEventReceiver rather than the state:

[SerializeField]
private AnimancerComponent _Animancer;

[SerializeField]
private SimpleEventReceiver _EventReceiver;

...

var state = _Animancer.Play(clip);
state.Events.OnEnd = ...;// See Animancer Events.
_EventReceiver.OnEvent.Set(state, ...);

It is recommended that you always use Set instead of only assigning the Callback to ensure that you only receive the callback from the state you specify. Otherwise events from an animation that is fading out might trigger a callback you just registered for a new animation that is fading in (because they are all using the same Function name).

The Golf Events example demonstrates the use of this feature.

End Animation Events

The EndEventReceiver component is similar to SimpleEventReceiver, except that it uses uses "End" as the Function name and instead of having its own callback, it triggers the End Event of the animation. You can already set End Events to occur at whatever time you want, so this is simply an alternative way of achieving the same thing.

The Golf Events example demonstrates the use of this feature.