This event has been superseded by the
AnimationTrack/GetMarkerReachedSignal|GetMarkerReachedSignal function. For more details, see Animation Events in the
articles/using animation editor|Using the Animation Editor article.
Fires every time playback of an
AnimationTrack reaches a
Keyframe that does not have the default name - “Keyframe”.
This event allows a developer to run code at predefined points in an animation (set by
Keyframe names). This allows the default functionality of Roblox animations to be expanded upon by adding
ParticleEffects at different points in an animation.
Keyframe names do not need to be unique. For example, if an Animation has three keyframes named “Particles” the KeyframeReached event will fire each time one of these keyframes is reached.
Keyframe names can be set in the Roblox Animation Editor when creating or editing an animation. They cannot however be set by a
Script on an existing animation prior to playing it.
The name of the
Create a localscript in StarterGui and paste the following code to try out this example.
The code in this sample will play an animation on the local character and print whenever a keyframe that is not named “Keyframe” is reached.
Listen For Animation Effects
The function in the following code sample provides an example of how the AnimationTrack.KeyframeReached event can be used to link different effects to an animation.
The function listens for any animations being played on the Humanoid (or AnimationController), and when a new animation is played listens for a keyframe named ‘Effect’ being reached. When a keyframe named ‘Effect’ is reached some basic particles will be emitted. Once the animation has stopped the connections used by the function are disconnected, in line with best practice to avoid memory leaks.
Although the particle effect in this sample is very simple, it could be substituted for a range of more complicated effects using the Sound, Beam, ParticleEffect or other objects. Additionally, in many cases the developer may only care about effects on one specific animation (rather than every animation played on a Humanoid). In this case, only the KeyframeReached portion of this sample would be needed.