KeyframeMarker

Show Deprecated

A KeyframeMarker is an instance meant to represent an event that will eventually be fired when a Keyframe is hit.

Using a KeyframeMarker

KeyframeMarkers should always be parented to a Keyframe via setting the parent directly or using the Keyframe:AddMarker() function of Keyframe. KeyframeMarkers can also be removed directly or using the Keyframe:RemoveMarker() function, and polled to check which markers are attached to a specific Keyframe using Keyframe:GetMarkers().

Whenever a Keyframe is detected as an animation is running, there will be an event fired for each KeyframeMarker that is parented to the Keyframe. These events are identifiable by the name of the KeyframeMarker. You can retrieve and listen to these events using the AnimationTrack.GetKeyframeMarkerReached function. Optionally, you may set the KeyframeMarker.Value property of the KeyframeMarker in order to pass along a value with the event being fired.

It inherits the Keyframe.Name property from Instance and behaves identically. Names are used for identification and no not need to be unique. When multiple KeyFrameMarkers with the same name are attached to a KeyFrame, events such as the one returned by AnimationTrack:GetMarkerReachedSignal() will fire for every marker.

See also:

Code Samples

Listening to Keyframe Markers

1local Players = game:GetService("Players")
2
3local player = Players.LocalPlayer
4local character = player.Character or player.Character:Wait()
5local humanoid = character:WaitForChild("Humanoid")
6
7-- Create new "Animation" instance
8local kickAnimation = Instance.new("Animation")
9-- Set its "AnimationId" to the corresponding animation asset ID
10kickAnimation.AnimationId = "rbxassetid://2515090838"
11
12-- Load animation onto the humanoid
13local kickAnimationTrack = humanoid:LoadAnimation(kickAnimation)
14
15-- Play animation track
16kickAnimationTrack:Play()
17
18-- If a named event was defined for the animation, connect it to "GetMarkerReachedSignal()"
19kickAnimationTrack:GetMarkerReachedSignal("KickEnd"):Connect(function(paramString)
20 print(paramString)
21end)
Get Keyframe Markers Attached to a Keyframe

1local keyframe = Instance.new("Keyframe")
2keyframe.Parent = workspace
3
4local marker1 = Instance.new("KeyframeMarker")
5marker1.Name = "FootStep"
6marker1.Value = 100
7
8local marker2 = Instance.new("KeyframeMarker")
9marker2.Name = "Wave"
10marker2.Value = 100
11
12keyframe:AddMarker(marker1) --marker.Parent = keyframe
13keyframe:AddMarker(marker2) --marker.Parent = keyframe
14
15local markers = keyframe:GetMarkers()
16for _, marker in pairs(markers) do
17 print(marker.Name)
18end

Summary

Properties

A value that is specified for a KeyframeMarker.

Events

Methods

Properties

Value

A value that is specified for a KeyframeMarker. Whenever the signal created from AnimationTrack:GetMarkerReachedSignal() gets fired, this value will be passed into the connected function.

See also:

Events

Methods