GatheredAnimationEvent
An animation event that a clip timer crossed, with the function name, the parameters, and the time of the event.
Read time 3 minutesLast updated 3 hours ago
Definition
- Type: Struct
- Namespace: Unity.Animations
- Assembly: UnityEngine.AnimationCoreModule
public struct GatheredAnimationEvent
Remarks
Pass a to AnimationEventUtility.GatherAnimationEvents to get the animation events that a timer crossed. The clip data stores the function name and the parameters of each event, so you can read them from jobs and Burst-compiled code. The function name and the string parameter are stored as StringHash values. Compare them to values that you compute on the main thread. The object reference parameter is an . Use GatheredAnimationEvent.EventIndex to read the complete event from the source animation clip on the main thread.
NativeList<GatheredAnimationEvent>new StringHash("name")EntityIdThe following example uses the , , , , , and namespaces. It gathers the animation events that the playback time of a clip passes between two updates. It then uses the event index of each gathered event to read the function name of the event from the animation clip.
System.Collections.GenericUnity.AnimationsUnity.CollectionsUnity.EntitiesUnity.IntegerTimeUnityEngineAdditional Resources: AnimationEventUtility
Examples
// This example reads the function name of each animation event that the clip time// crosses between two updates.public static List<string> GatherEventFunctionNames( AnimationClip animationClip, float previousTime, float currentTime){ using BlobObjectReference<Clip> clipReference = animationClip.ToClipReference(); // Stop if the animation clip is null or has no clip data. if (!clipReference.IsValid) { return new List<string>(); } AnimationEvent[] clipEvents = animationClip.events; // Gather the events from previousTime (excluded) to currentTime (included), in seconds from the start of the clip. // To step over the end of a looping clip, pass a currentTime that is greater than the length of the clip. // When previousTime is greater than currentTime, the clip plays backward and the events come in descending order. using NativeList<GatheredAnimationEvent> gatheredEvents = new NativeList<GatheredAnimationEvent>(Allocator.Temp); AnimationEventUtility.GatherAnimationEvents( ref clipReference.Value, new DiscreteTime(previousTime), new DiscreteTime(currentTime), gatheredEvents); // The event index of each gathered event is its index in AnimationClip.events. List<string> functionNames = new List<string>(); foreach (GatheredAnimationEvent gatheredEvent in gatheredEvents) { AnimationEvent clipEvent = clipEvents[gatheredEvent.EventIndex]; functionNames.Add(clipEvent.functionName); } // For events at 0.25 and 0.75 seconds in a looping clip of 1 second, a range from 0.6 to 1.3 returns // the 0.75 event, then the 0.25 event of the next loop. return functionNames;}
Fields
Value | Description |
|---|---|
| EventIndex | The index of the event in the events of the source animation clip. |
| FloatParameter | The float parameter value that the event stores. |
| FunctionName | The hash of the name of the function of the event. |
| IntParameter | The int parameter value that the event stores. |
| Loop | The loop count of the clip cycle in which the timer crossed the event, as a TimerState.LoopCount value. |
| ObjectReferenceParameter | The object reference parameter of the event, or |
| StringParameter | The hash of the string parameter of the event. |
| Time | The time of the event on the curves of the clip, in seconds. |