AnimationTrack.MarkerReached event

As a Roblox developer, it is currently too hard to use animation markers for local effects. I have used GetMarkerReachedSignal extensively in several projects to make visuals or sounds perfectly sync to character animations. I really like this solution but it has some quirks.

Animation markers are powerful for this use case thanks to their optional parameter field. For example, there could be any number of markers called “PlaySound” and the parameter would specify what sound to play when the marker is reached. While it is possible to do this already, the API for markers is quite lacking, making it difficult to scale.

Currently, the only API we have involving markers is AnimationTrack:GetMarkerReachedSignal. Although this is useful, it has limitations. There’s no way to determine what markers an AnimationTrack has in code without manually storing this information somewhere. In comparison, when using named keyframes, there is both a KeyframeReached event and a GetTimeOfKeyframe method.

Consider that with KeyframeReached, it’s still possible to respond to specific keyframe names with simple logic, despite not having a GetKeyframeReachedSignal event:

Track.KeyframeReached:Connect(function(Keyframe)
    if Keyframe == "DoSomething" then
        print("Did something")
    elseif Keyframe == "DoSomethingElse" then
        print("Did something else")
    end
end)

But GetMarkerReachedSignal requires you to know exactly which markers any given animation has, which is very inconvenient. If a MarkerReached event, a GetTimeOfMarker method, or even a GetMarkers method were added to animation tracks, it would eliminate this issue.

If Roblox is able to address this issue, it would improve my development experience because I wouldn’t have to store marker information for every animation in my experience. My current project already has over 100 animations, with a large number of them having markers for sound effects. Animation markers are a really nice feature and this is the main thing I feel they are missing.

9 Likes

You can already implement this behavior yourself if you’re using KeyframeSequences:

local function getMarkers(keyframeSequence: KeyframeSequence): {KeyframeMarker}
    local markers = {}

    for _, keyframe in keyframeSequence:GetKeyframes() do
        for _, marker in keyframe:GetMarkers() do
            table.insert(markers, marker)
        end
    end

    return markers
end
1 Like

The feature request is for animation tracks, not keyframe sequences.

1 Like

To add onto this, you can use KeyframeSequenceProvider:GetKeyframeSequenceAsync(\<Animation ID>) if you only have the ID of the animation.

1 Like

Bump. This is a heavily needed feature that should be relatively easy to implement and would have some very good use cases

1 Like