Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


AnimationEventInfo

AnimationEventInfo is a read-only, non-allocating struct that provides information about an animation event when it fires.
Read time 2 minutesLast updated 4 days ago

Definition

  • Type: Struct
  • Namespace: UnityEngine
  • Assembly: UnityEngine.AnimationModule
public ref struct AnimationEventInfo

Remarks

AnimationEventInfo is a ref struct that serves as a read-only view of animation event data when an event is fired during animation playback. Unlike AnimationEvent, AnimationEventInfo is designed for reporting event information in callbacks. It cannot be used for authoring or be stored in fields.
An animation event callback can accept either an AnimationEvent or an AnimationEventInfo parameter. Use AnimationEventInfo to avoid allocating the AnimationEvent object itself when an event fires.
The parameter can access floats, ints, strings, and object references configured on the animation event.
Note: The AnimationEventInfo struct itself doesn't allocate but accessing string properties (_functionName and _stringParameter) causes string allocation when retrieving from native code. Accessing non-string properties (such as
time
,
floatParameter
,
intParameter
,
objectReferenceParameter
,
isFiredByLegacy
,
isFiredByAnimator
,
animatorStateInfo
, and
animatorClipInfo
) causes no allocations.
A more detailed example shows how to access animator state information:

Examples

// AnimationEventInfo example // Non-allocating event callback that reads event parametersusing UnityEngine;public class Example : MonoBehaviour{ // This callback receives AnimationEventInfo instead of AnimationEvent // which avoids allocations when the event fires public void OnAnimationEvent(AnimationEventInfo eventInfo) { Debug.Log($"Event '{eventInfo.functionName}' fired at time {eventInfo.time}"); Debug.Log($"Parameters: int={eventInfo.intParameter}, float={eventInfo.floatParameter}"); Debug.Log($"String parameter: {eventInfo.stringParameter}"); if (eventInfo.objectReferenceParameter != null) { Debug.Log($"Object reference: {eventInfo.objectReferenceParameter.name}"); } }}
// Accessing animator state information from AnimationEventInfousing UnityEngine;public class Example : MonoBehaviour{ public void OnAnimatorEvent(AnimationEventInfo eventInfo) { // Check the event source if (eventInfo.isFiredByAnimator) { // Access animator state information AnimatorStateInfo stateInfo = eventInfo.animatorStateInfo; Debug.Log($"State: {stateInfo.fullPathHash}, Time: {stateInfo.normalizedTime}"); // Access clip information AnimatorClipInfo clipInfo = eventInfo.animatorClipInfo; if (clipInfo.clip != null) { Debug.Log($"Clip: {clipInfo.clip.name}, Weight: {clipInfo.weight}"); } } else if (eventInfo.isFiredByLegacy) { // Access legacy animation state AnimationState animState = eventInfo.animationState; if (animState != null) { Debug.Log($"Animation: {animState.name}, Time: {animState.time}"); } } }}

Properties

Property

Description

animationStateThe animation state that fired this event (Read Only).
animatorClipInfoThe animator clip info related to this event (Read Only).
animatorStateInfoThe animator state info related to this event (Read Only).
floatParameterFloat parameter that is stored in the event (Read Only).
functionNameThe name of the called function (Read Only).
intParameterInteger parameter that is stored in the event (Read Only).
isFiredByAnimatorReturns true if this animation event was fired by an Animator component (Read Only).
isFiredByLegacyReturns true if this animation event was fired by an Animation component (Read Only).
objectReferenceParameterObject reference parameter that is stored in the event (Read Only).
stringParameterString parameter that is stored in the event (Read Only).
timeThe time at which the event is being fired (Read Only).