Revamped Animation Events

Previously, in order to perform some logic once a Keyframe has been hit in an animation, you would have to name the Keyframe and then listen for the KeyframeReached signal on an Animation Track. However, this would fire for any Keyframe and then you would have to check against the Keyframe name first. You can see this old flow here.

We’ve decided to clean up this flow a bit and also have it be more integrated within the Animation Editor. This is where Keyframe Markers come in. Please be aware that we did not remove the old flow, and anyone using KeyframeReached for animation events should not experience any changes.

What are Keyframe Markers?

Keyframe Markers are new instances that are parented to a Keyframe. Whenever a Keyframe is hit on an Animation Track, we now look through all of the markers that are parented to the Keyframe and fire a corresponding event. You can connect to a marker by name, similar to how you would do with Instance:GetPropertyChangedSignal. Keyframe Marker’s also have a value property, which is a string parameter value meant to be passed to the event handler.

In the Animation Editor

The Animation Editor now has a new section of the timeline dedicated to Animation Events:

Events also get their own icon, separate from Keyframes and Poses, to make it easier to identify at what times events will be fired in your animation:

43%20PM

You can add new events via right-clicking on the area of the timeline containing the event icons, or click the “Create Event Button” to the left of the timeline area:

53%20PM

There is a specific window for editing all of the events that a particular Keyframe has. Here you can specify the name of the event upon adding as well as the optional parameter that will be passed to your connecting function in script:

00%20PM

In Script

If we wanted to use this new animation event system to play sound effects whenever the player’s foot touches the ground, we could create an event called “FootStep” in the editor and then place that event on any keys where the foot hits the ground. Let’s also pass a parameter value for the volume of the sound.

26%20PM

In Script, assuming you have access to both the Animation Track for this animation and a sound effect that you would like to play, the code would look something like this:

animationTrack:GetMarkerReachedSignal("FootStep"):Connect(function(value)
    footStepSound.Volume = tonumber(value)
    footStepSound:Play()
end)

We hope you enjoy this feature and find it useful. Please let us know if you encounter any inhibiting bugs or have ideas to improve it.

206 Likes

Awesome! Keyframe naming has been hit or miss for awhile in the new animation editor (sometimes unavailable).

I’m glad to see this addition!

4 Likes

This is perfect timing, I was just about to do some Animation Keyframe scripting!

2 Likes

Wow!! This is such a nice, unexpected feature. Thank you for this!

12 Likes

Great! Now please fix the easing styles

10 Likes

So this is the information I was searching for, regarding keyframe markers. I notice that I use keyframes quite a bit as of late. My previous production workflow was even worse: I used waits, not properties of AnimationTracks, to perform actions.

cc @xsixx for MAS pls

4 Likes

Any animation update is welcome in my book. Hope to see more soon!

1 Like

This is super awesome and adds a lot more character to animations. Better animation tools are always appreciated! Always happy to see the changes that mean an improved backend for developers with more intuitive features.

Really useful!
I was making some footstep animations few days ago and stumbled upon keyframes.
They were pretty chunky to work with, so I’m definitely hyped for this.

1 Like

This update couldn’t have come at a better time, I was going to make some animations that would need to be monitored by code (usually with wait()s) to cue certain events, now, people don’t need to do that.

This is an amazing update, definitely a step in the right direction.

now fix everything else wrong with the animation editor [joke]

7 Likes

This is pretty nice,

This would be great

Great addition! This makes me wonder if there are any plans to add footstep events to all default walking/running animations for developers who wish to have more complex footstep sound systems. I’ve created one where it uses named “Footstep” keyframes to pick a random sound from a material sound set of the material the player is currently walking on and would LOVE to be able to use it with default animations.

3 Likes

This is much better. Thank you!

1 Like

Long overdue, great update!

Great update! However I still wish we could have much more control over animations, such as integrating a function that would allow us to compile a KeyframeSequence to an Animation in a script, which would allow for more dynamic animations instead of these premade editor-exported ones. (changing Transform is also an option of course but I do not think it is very efficient to touch on)

The code in the OP is invalid and will not run if copied!

Connect needs to be invokved using : not .

3 Likes

Fixed, good catch

2 Likes

I didn’t even know this was possible… So much opportunity has just opened up! Good update too!

3 Likes