PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

GetMarkerReachedSignal

This function returns an DataType/RBXScriptSignal|event similar to the AnimationTrack/KeyframeReached event, except it only fires when a specified KeyframeMarker has been hit in an Animation|animation. The difference allows for greater control of when the event will fire.

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 things such as Sound|Sounds or ParticleEmitter|ParticleEffects at different points in an animation.

To learn more about using this function, see Animation Events in the articles/using animation editor|Using the Animation Editor article.

Using the Returned Event

The RBXScriptSignal (event) returned by this can be connected to another function. The connection creates a DataType/RBXScriptConnection listener that executes the connected function every time the animation hits the specified KeyframeMarker until disconnected using Disconnect().

More about Keyframes

Keyframe names do not need to be unique. For example, if an Animation has three keyframes named “Particles” the connected event returned by this function 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.

See also

  • AnimationTrack, controls the playback of an animation on a Humanoid or AnimationController
  • Keyframe, holds the Pose|Poses applied to joints in a Model at a given point of time in an animation
  • Keyframe/AddMarker
  • Keyframe/RemoveMarker
  • Keyframe/GetMarkers

Parameters

Name Type Default Description

The name of the KeyFrameMarker the signal is being created for

Returns

Return Type Summary

The signal created and fired when the animation reaches the created KeyFrameMarker


Code Samples


Listening to KeyFrameMarkers

The following example plays an animation on the local Player/Character|character and prints a value whenever a Keyframe that has a KeyframeMarker named “FootStep” gets hit in the Animation|animation.

The example listens to when the KeyFrame is hit by connecting the function markerReached to the event returned by AnimationTrack/GetKeyframeReachedSignal, which fires whenever the KeyFrameMarker named “FootStep” gets hit.

In order for this to work as expected, it should be placed in a LocalScript in StarterGui.

local player = game.Players:GetChildren()[1]
local character = game.Workspace:WaitForChild(player.Name)
local humanoid = character:WaitForChild("Humanoid")
 
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://437855404"
local animTrack = humanoid:LoadAnimation(anim)
 
animTrack:GetKeyframeReachedSignal("FootStep"):Connect(function(value)
    print(value)
end)
animTrack:Play()