Events
Overview
Quantum Animator provides support for Instant
events and Time-Window
events.
Creating a New Instant Event
Events assets can be created using Create->Quantum->Assets...

Instant Events will trigger only one time the Execute()
function once the Animator plays the clip that contains such event baked. A good pattern is to inherit from the base AnimatorInstantEventAsset
and override the base class methods with different procedures, like custom Frame.Siganls
.
C#
public abstract class AnimatorInstantEventAsset : AnimatorEventAsset, IAnimatorEventAsset
{
/// <inheritdoc cref="AnimatorEventAsset.OnBake"/>
public new AnimatorEvent OnBake(AnimationClip unityAnimationClip, AnimationEvent unityAnimationEvent)
{
var quantumAnimatorEvent = new AnimatorInstantEvent();
quantumAnimatorEvent.AssetRef = Guid;
quantumAnimatorEvent.Time = FP.FromFloat_UNSAFE(unityAnimationEvent.time);
return quantumAnimatorEvent;
}
}
Event Setup
Follow these steps to define the event on an animation clip:
- Add the
AnimationEventData
component to the same GameObject the containsAnimator
component, in yourQuantumEntityPrototype
:

- On the Animation window select the clip and add a new
Unity AnimationEvent
:

- Select the created event and specify the
Function
andObject
as the image below:

Creating a New Time-Window Event
The procedure is very similar to the instant event creation, the difference here is that you will need to create a second event of the same type in the Unity Clip to define the final of the event execution.

In case you want to create new events that have a similar behavior with OnEnter()
, Execute()
and OnExit()
methods, by inherit the AnimatorTimeWindowEventAsset
class:
C#
/// <summary>
/// This is a sample of how to use SampleTimeWindowEvent events. Use it as a base to create a new class inheriting from AnimatorInstantEventAsset and
/// implement a custom logic on Execute method
/// </summary>
[Serializable]
public class ExampleTimeWindowEventAsset : AnimatorTimeWindowEventAsset
{
public override unsafe void OnEnter(Frame f, AnimatorComponent* animatorComponent, LayerData* layerData)
{
Debug.Log($"[Quantum Animator ({f.Number})] OnEnter animator time window event.");
}
public override unsafe void Execute(Frame f, AnimatorComponent* animatorComponent, LayerData* layerData)
{
Debug.Log($"[Quantum Animator ({f.Number})] Execute animator time window event.");
}
public override unsafe void OnExit(Frame f, AnimatorComponent* animatorComponent, LayerData* layerData)
{
Debug.Log($"[Quantum Animator ({f.Number})] OnExit animator time window event.");
}
}
Back to top