Animation Events
Create and capture animation events to run functions in code when your animation hits a specific location.
Last updated
Create and capture animation events to run functions in code when your animation hits a specific location.
Last updated
In Airship animation events are passed to Typescript through the AnimationEventListener component. If you add this component to your animator it will pass along events from your animations. Airship Characters have this component by default.
To setup an event use Unity's animation event system either in the animation clip itself using the animation window, or on an FBX using the inspector window.
Create a new animation event
Give it the function TriggerEvent
Set the triggers key to be whatever you would like to identify it by
To listen to events in Typescript, get the component reference for the AnimationEventListener, then connect to the OnAnimationEvent Signal on Character.animator:
//Get the component (or you can setup a reference if in an AirshipBehaviour)
const events = this.gameObject.GetComponent<AnimationEventListener>();
if(events){
//Connect to simple events
events.OnAnimEvent((key)=>{
//Key is the string value you specify in editor
if(key === "MyAnimationEvent"){
///Do Stuff
print("Heard my event!");
}
})
}
If you need additional data passed along with the event, you can include an AnimationEventData scriptable object.
In your project, right click to Create -> Airship -> Animation Event Data
Fill in the objects data with whatever you want to receive in TS
On your animation, Set the event function to TriggerEventObj
Set the Object variable to the Animation Event Object you created
Now to receive this event in Typescript
//Get the component (or you can setup a reference if in an AirshipBehaviour)
const events = this.gameObject.GetComponent<AnimationEventListener>();
if(events){
//Connect to object event
events.OnAnimObjEvent((data)=>{
//key is used to identify the event
if(data.key === "MyAnimationEventObj"){
///Do Stuff with the extra data
print("New Float: " + data.floatValue);
}
})
}