It's often necessary to do things at a certain time during an animation, for example:
- Golf Events: hit a golf ball when your swing passes a certain point.
- Footstep Events: play a footstep sound each time a foot touches the ground during a walk animation.
You could script these things using coroutines or other timers, but Unity's inbuilt Animation Events and Animancer's custom event system allow you to configure the events as part of the animation so you can easily tweak the exact timing you want while previewing the animation. The following table summarises the differences between the two event systems.
Animation Events | Animancer Events |
---|---|
Built into Unity. They work the same with Animancer as without it. |
Animancer Lite allows you to try out Animancer Events in the Unity Editor, but they won't be available in Runtime Builds unless you purchase Animancer Pro. End Events are fully usable in Animancer Lite though. |
How to use:
|
How to use:
|
Animation Events are defined as part of an AnimationClip so every state using that clip will have the same events. |
Animancer Events are defined separately from the AnimationClip so you can use different sets of events for the same animation. If you want to share a set of events, you can simply define them in a shared location such as by using a Transition Asset. |
Each Animation Event calls one method which must be located in a component on the same GameObject as the Animator . |
Animancer Event callbacks can be registered from anywhere so you have full control over the structure of your code. They can also be configured in the Inspector using UnityEvents or UltEvents . |
The method can have at most one parameter of any of the following types: float , int , string , anything derived from UnityEngine.Object , or AnimationEvent which contains one of each of the other types as well as several other details. |
Animancer Event callbacks registered in code can have any type of parameter. UnityEvents and UltEvents support limited parameter types as explained in this feature comparison.
|
Animation Events aren't very efficient because they use a mechanism similar to GameObject.SendMessage and if the event has a string or AnimationEvent parameter, it will create some Garbage every time it's triggered which can potentially cause performance issues. |
Animancer Events are much more efficient because they use C# Delegates. Animancer Events configured in the Inspector usingUnityEvents don't allocate Garbage. UltEvents don't usually do so either, except in certain circumstances such as when a method returns a value type (UnityEvents simply wouldn't be able to call such a method though). |
Animation Events can be added at runtime, but they're still subject to all the above limitations. If you're using an Animator Controller, you don't even have access to the AnimationClip of a particular state until it's already playing. |
Animancer Events can be added at runtime using Delegates. For example: state.Events.Add(0.5f, () => Debug.Log("Event Triggered")); . |
Methods are referenced using raw string s. If the method is renamed, you need to manually find and update all Animation Events in any animations that were using it. |
Animancer Events can be used without any string s, but are often given String Assets as names to allow their callbacks to be set in code while configuring the event times in the Inspector so you can preview what the model looks like while doing so. |
Animation Events | Unity's inbuilt Animation Event system. |
Animancer Events | Animancer's custom event system. |
End Events | A special Animancer Event specifically for ending the animation (usually by playing something else). |