This event fires whenever the
AnimationController begins playing an animation. It returns the
AnimationTrack can be used to access the animation’s playback functions and events. It will only fire for animations playing on the specific
Humanoid/AnimationPlayed for the
Humanoid variant of this function.
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.