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...
![EventAsset creation](/docs/img/quantum/v3/addons/animator/animator-events-01.png)
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
:
![EventAsset creation](/docs/img/quantum/v3/addons/animator/animator-events-02.png)
- On the Animation window select the clip and add a new
Unity AnimationEvent
:
![EventAsset creation](/docs/img/quantum/v3/addons/animator/animator-events-03.png)
- Select the created event and specify the
Function
andObject
as the image below:
![EventAsset creation](/docs/img/quantum/v3/addons/animator/animator-events-04.png)
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.
![EventAsset creation](/docs/img/quantum/v3/addons/animator/animator-events-05.png)
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