GetKeyframeSequenceAsync not working correctly if called in fast succession in coroutine

(Note: I’d post this in the Bugs section but I can’t create a topic there.)

I have the following issue, which seems like a bug in the KeyframeSequenceProvider:GetKeyframeSequenceAsync function.

If you call KeyframeSequenceProvider:GetKeyframeSequenceAsync multiple times in quick succession inside a coroutine it won’t correctly download the animation.

Where it happens: when running the game from Studio.

When it happens: as soon as the code is ran at start (it seems that if the animation loads that this error does not happen, so the example script must be ran as soon as possible).

Reproduction steps:

  1. Create a part
  2. Attach the given script to it
  3. Run the game: the error should trigger.

What should happen:
The keyframes with 2 animation markers should load: “AttackStart” and “AttackEnd”.

What actually happens:
The keyframes are missing, so the markers are also not loaded.
Though if you continue from the 1st error sometimes the animation keys are then loaded correctly.

This is the script to execute, just attach it to any part.

local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")

for i=1,5 do
	
	coroutine.wrap(function()
		local KeyframeSeq = KeyframeSequenceProvider:GetKeyframeSequenceAsync("rbxassetid://6979253696") 

		print("!!!!! Printing: ")
		local bWereMarkersFound = false
		
		local Keyframes = KeyframeSeq:GetKeyframes()
		for _,Keyframe in pairs(Keyframes) do
			local MarkersInKeyframe = Keyframe:GetMarkers()
			for _,IterMarker in pairs(MarkersInKeyframe) do
				bWereMarkersFound = true
				print("!!!!! Marker: " .. tostring(IterMarker.Name))
			end
		end
		
		if bWereMarkersFound == false then
			error("markers not found")
		end

		
	end)()
	
end
1 Like

Thanks for the report! We’ve filed a ticket to our internal database and we’ll follow up when we have an update for you.

3 Likes

Is there any way we could get timing information on how to avoid this? I ran into this problem today.

This is very annoying. Something is caching the results incorrectly, so attempting to fetch the same assetid twice just gives you an empty keyframe sequence. Please resolve this ASAP!

1 Like

Still an issue, and is especially detrimental to our game. I rely on keyframe and pose data derived from KeyframeSequenceProvider for weapon hitboxes, and currently this makes it impossible to make my hitboxes work again.
I am preloading 30+ animations, so adding even a small yield would be detrimental.

2 Likes

Reviving this post to add more info and a possible solution to others who might come to this post in the future.

It’s 2024 and this still happens, but only sometimes.

The docs say:

So now we can use AnimationClipProvider to get the same result and it doesn’t seem to have this problem. Using the GetAnimationClipAsync method.

What seems to happen is that the KeyframeSequenceProvider cache sometimes doesn’t work.

You can test this cache by calling it multiple times and setting its parent to a folder in the workspace, rather than creating multiple KeyframeSequences it will just reuse the same one. Therefore, you may want to clone the returned sequence if you need to move it around.

local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
local AnimationClipProvider = game:GetService("AnimationClipProvider")
for i = 1, 3 do
  task.spawn(function () -- run it "in a parallel thread"
    local KS_KeyframeSequenceProvider = KeyframeSequenceProvider:GetKeyframeSequenceAsync("rbxassetid://10714347453")
    KS_KeyframeSequenceProvider.Parent = workspace.Terrain
    KS_KeyframeSequenceProvider.Name = "KeyframeSequenceProvider-" .. i

    local KS_AnimationClipProvider = AnimationClipProvider:GetAnimationClipAsync("rbxassetid://10714347453")
    KS_AnimationClipProvider.Parent = workspace.Terrain
    KS_AnimationClipProvider.Name = "AnimationClipProvider-" .. i
  end)
end

I tested AnimationClipProvider for some time and so far the problem has not occurred.