Getting a table with all animation events from an animation

I’m trying to get a table with all the animation events of an animation.
I found this code from an older post:

function module.GetAllAnimationEvents(animation : Animation)
	local markers: table = {}
	local ks: KeyframeSequence = sequenceProvider:GetKeyframeSequenceAsync(animation.AnimationId)
	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

But it says the sequenceProvider was deprecated. I tried using animationClipProvider but it didn’t work (it returned an empty table). Is there a method for this that isn’t deprecated or how can I make it work with animationClipProvider?

1 Like

Did you try this?

This is where I got the code snippet from. As you can see, it used keyframeSequenceProvider which is now deprecated.

yeah but does it work? deprecated doesn’t mean broken

It says it’s very slow in the output

I’ll recommend using it and only calling it once when the game starts then storing the results in a module, to when you need the events you read the stored results.


to be honest I didn’t even know keyframeSequenceProvider exists, and was getting the events in another (weird?) way

local InsertService = game:GetService("InsertService")

function GetAnimationEvents(animID: number)
	local AnimationKeyFrames = InsertService:LoadAsset(animID)
	AnimationKeyFrames.Parent = game.ServerStorage
	
	local events = {}
	
	for i,v in AnimationKeyFrames:GetDescendants() do
		if v:IsA("KeyframeMarker") then
			local keyFrame = v.Parent
			print(keyFrame) -- !!!
			table.insert(events,v)
		end
	end
	
	print(events)	
	
	return events
end

GetAnimationEvents(14913301778)

and you can get the event time if you need it from the parent KeyFrame

1 Like