Behaviour

The Events page compares the differences between Unity's inbuilt Animation Events and Animancer Events and this page explains several other important details about the way Animancer Events work.

Looping

Events behave differently depending on whether the animation is looping or not:

Type Trigger Conditions
Non-Looping Once on the frame when the animation passes the specified time.
Looping

Every loop on the frame when the animation passes the specified time.

  • If the animation is playing fast enough that multiple loops pass in a single frame, the event will be triggered the appropriate number of times. If you want to ensure that your callback only gets triggered once per frame, you can store the AnimancerGraph.FrameID and check if it has changed each time your method is called.
  • Looping Events must be within the range of 0 <= normalizedTime < 1 in order to function correctly. Events outside that range will cause an ArgumentOutOfRangeException during the next update.
  • AnimancerEvent.AlmostOne is a constant containing the largest possible float value less than 1 in case you want to set an event to occur right at the end of the loop.
End Events On every frame when the animation has passed the specified time, regardless of whether the animation is looping or not.

Other Details

This system has several other details worth mentioning:

  • Changing the AnimancerState.Time (or NormalizedTime) prevents that state from triggering any more events during that frame. If you want events between the old and new time to be triggered, you can use AnimancerState.MoveTime instead.
  • The AnimancerState.Events sequence can not be modified by its own events (i.e. you can't use an event to add another event to the state that triggered it).
  • Animancer Events can be placed on Mixers or on their children depending on whether you want them to be triggered according to the weighted average NormalizedTime of the children or the NormalizedTime of a specific child. The Events section on that page gives more details.
  • They also technically work with Controller States, though they are tied to the overall ControllerState and do not check what the Animator Controller is doing internally so attempting to use them might not give the intended result.
  • If you want to run custom code as part of the animation update, you can implement IUpdatable in your own scripts.