How can i get a table that contains all the animation events of an animation?

Hello, i’m trying to figure out if there’s a way to get all the animation events that are in an animations in a table, so i can loop in it and attach a animTrack:GetMarkerReachedSignal() to each one.
I searched on google, but did find nothing that could help. i was expecting a method, something like animTrack:GetMarkers()
For now i’m using a table created by me, that contains the name of all the animation events that are in all the animations, but i don’t really like this way. Does an automatic way to do this exist?
Any reply is appreciated.

2 Likes

You could do a for loop for the animation events using :GetChildren().

mhhh, does GetChildren get the animation events of an animation track? i mean, i need to get that table, from the animationTrack.

According to a Roblox Developer Article, I believe so.

I tried animTrack:GetChildren() and it shows up that it is empty. The new roblox output can now show tables. table: 0x56d5904006acd8dc {}

Did you use a for loop for the animationTracks?

I load all the animations to the humanoid, and put the animTrack into a table.
Then i loop into that table, and do print(animTrack:GetChildren)

something like this:

local huma = --humanoid patch
local tracks = {}

for a,b in pairs(animationsObj) do
    local loaded = huma:LoadAnimation(b)

    repeat
        wait()
    until loaded.Length ~= 0

    tracks[b.Name] = loaded
end

for a,b in pairs(tracks) do
    print(b:GetChildren()) --table: 0x56d5904006acd8dc {}
end

You can get all the events from an animation like this.

local sequenceProvider = game:GetService("KeyframeSequenceProvider")

local function getAllAnimationEventNames(animID: string): table
	local markers: table = {}
	local ks: KeyframeSequence = sequenceProvider:GetKeyframeSequenceAsync(animID)
	local function recurse(parent: Instance): void
		for _, child in pairs(parent:GetChildren()) do
			if (child:IsA("KeyframeMarker")) then
				table.insert(markers, child)
			end
			if (#child:GetChildren() > 0) then
				recurse(child)
			end
		end
	end
	recurse(ks)

	return markers
end

local markersForAnimation: table = getAllAnimationEventNames("rbxassetid://5936670291")
print(markersForAnimation)

image

20 Likes

Thanks, really, it works perfectly! :grinning:

Welcome. It’s a little-known part of the Roblox API so it definitely was harder to find.

2 Likes