KeyframeSequenceProvider

Show Deprecated
Not Creatable
Service
Not Replicated

The KeyframeSequenceProvider service provides functions to load and preview KeyframeSequences. It includes a number of functions that are useful when working with Animations.

What is a KeyframeSequence?

A KeyframeSequence stores a series of Poses that encode the hierarchy and motion of an animation. The animation data Roblox uses in the playback of an animation, referenced by the Animation.AnimationId property, can be constructed from a KeyframeSequence. KeyframeSequences are usually created by the Roblox Animation Editor but can be created through other plugins or even manually.

For more information, see the KeyframeSequence page.

What does the KeyframeSequenceProvider do?

The KeyframeSequenceProvider has a number of uses.

  • Download the KeyframeSequence associated with an animation content ID from the Roblox website
  • Generate a temporary id to locally preview an animation
  • Fetch the content IDs of animations owned by a particular user.

Code Samples

Create temporary animation

1local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
2
3local function createPreviewAnimation(keyframeSequence)
4 local hashId = KeyframeSequenceProvider:RegisterKeyframeSequence(keyframeSequence)
5 if hashId then
6 local Animation = Instance.new("Animation")
7 Animation.AnimationId = hashId
8 return Animation
9 end
10end
11
12local keyframeSequence = Instance.new("KeyframeSequence")
13
14local animation = createPreviewAnimation(keyframeSequence)
15
16print(animation)

Summary

Properties

Events

Methods


Returns a Lua table with memory usage for all animations stored in the cache.


Generates a temporary asset ID from a KeyframeSequence that can be used for localized testing of an animation. Generates an active:// URL.

RegisterKeyframeSequence(keyframeSequence: Instance): Content  

Generates a temporary asset ID from a KeyframeSequence that can be used for localized testing of an animation. Generates a hash.

GetAnimations(userId: number): Instance  YIELDS

This function returns an InventoryPages object which can be used to iterate over animations owned by a specific user.


Returns a KeyframeSequence based on the specified assetId asynchronously.

Properties

Events

Methods

GetMemStats

Roblox Script Security

Returns a Lua table with memory usage for all animations stored in the cache. The memory reported is a summation of all of the memory used in any of the animation caches stored by the KeyframeSequenceProvider.


Returns

A Lua table with key storing the animation names and value returning the amount of memory used by that animation.

RegisterActiveKeyframeSequence

Generates a temporary asset ID from a KeyframeSequence that can be used for localized testing of an animation.

This function performs the same function to KeyframeSequenceProvider:RegisterKeyframeSequence() however this function generates an active:// URL instead of a hash.

The ID generated can be used in an Animation's Animation.AnimationId property for testing.

The asset ID generated by this function is temporary and cannot be used outside of Studio. Developers wishing to generate an asset ID that can be used online should upload the KeyframeSequence to Roblox.

Parameters

keyframeSequence: Instance

The KeyframeSequence to be used.


Returns

A temporary asset ID generated for localized animation playback.

Code Samples

Create temporary animation

1local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
2
3local function createPreviewAnimation(keyframeSequence)
4 local hashId = KeyframeSequenceProvider:RegisterKeyframeSequence(keyframeSequence)
5 if hashId then
6 local Animation = Instance.new("Animation")
7 Animation.AnimationId = hashId
8 return Animation
9 end
10end
11
12local keyframeSequence = Instance.new("KeyframeSequence")
13
14local animation = createPreviewAnimation(keyframeSequence)
15
16print(animation)

RegisterKeyframeSequence

Generates a temporary asset ID from a KeyframeSequence that can be used for localized testing of an animation.

This function performs the same function to KeyframeSequenceProvider:RegisterActiveKeyframeSequence() however this function generates a hash instead of an active:// URL.

The ID generated can be used for the Animation.AnimationId property to test animations.

The asset ID generated by this function is temporary and cannot be used outside of Studio. Developers wishing to generate an asset ID that can be used online should upload the KeyframeSequence to Roblox.

Parameters

keyframeSequence: Instance

The KeyframeSequence to be used.


Returns

A temporary asset ID generated for localized animation playback.

Code Samples

KeyframeSequenceProvider:RegisterKeyframeSequence

1local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
2
3local asset = KeyframeSequenceProvider:RegisterKeyframeSequence(workspace.KeyframeSequence)
4
5local animation = Instance.new("Animation")
6animation.Name = "TestAnimation"
7animation.AnimationId = asset
8animation.Parent = workspace

GetAnimations

Yields

This function returns an InventoryPages object which can be used to iterate over animations owned by a specific user.

This function has a number of potential uses, such as allowing users to browse and import animations into a custom animation plugin.

Parameters

userId: number

The user ID of the user.


Returns

An InventoryPages of animations.

Code Samples

KeyframeSequenceProvider GetAnimations

1local KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
2
3local USER_ID = 0 -- Insert your UserId here
4
5local function extractPages(pagesObject)
6 local array = {}
7 while true do
8 local thisPage = pagesObject:GetCurrentPage()
9 for _, v in pairs(thisPage) do
10 table.insert(array, v)
11 end
12 if pagesObject.IsFinished then
13 break
14 end
15 pagesObject:AdvanceToNextPageAsync()
16 end
17 return array
18end
19
20local inventoryPages = KeyframeSequenceProvider:GetAnimations(USER_ID)
21
22local animationIds = extractPages(inventoryPages)
23
24for _, id in pairs(animationIds) do
25 print(id)
26end
27print("total: ", #animationIds)

GetKeyframeSequenceAsync

Yields

GetKeyframeSequenceAsync returns a KeyframeSequence based on the specified assetId. The assetId must correspond to an animation. The function will yield until the KeyframeSequence is loaded from the website. Because this is a webcall it should wrapped in a pcall.

Parameters

assetId: Content

The content ID of the animation.


Returns

Code Samples

KeyframeSequenceProvider:GetKeyframeSequenceAsync

1local KeyframeSequence = game:GetService("KeyframeSequenceProvider")
2
3local ANIMATION_ID = "rbxassetid://507771019"
4
5local keyframes = {}
6
7local success = pcall(function()
8 keyframes = KeyframeSequence:GetKeyframeSequenceAsync(ANIMATION_ID)
9end)
10
11if success then
12 local keyframeTable = keyframes:GetKeyframes()
13 for key, value in ipairs(keyframeTable) do
14 print("The time of keyframe number", key, "is", value.Time)
15 end
16else
17 print("error getting KeyframeSequence")
18end