Provide a way for us to know when an AnimationTrack is fully loaded

It is difficult to reliably use animations as there are no good ways to detect when an AnimationTrack is loaded and ready to actually start modifying CFrames or have properties be changed or read.

It is important to have this capability; three use cases are:

  • When switching between two animations, we want to keep the old one playing until the new one is ready, so that the character doesn’t switch in and out of the default pose.
  • Doing pre-processing work which reads the animated CFrame of the rig (we need to know that the animation is actually affecting the rig before we read it).
  • This post: AnimationTrack.Looped property should not have a latency

I know of one way to detect an animation being loaded: we can check the values of any properties which are only set if the animation is loaded. For example, if AnimationTrack.Length is greater than zero, or if AnimationTrack.Looped is true.

However this method does not work very well for three reasons:

  1. Not documented or officially supported
  2. We have to poll the properties we care about (there are no signals)
  3. The values of the properties before loading may be the same as the values of the properties after loading, making them indistinguishable. (This is particularly annoying for AnimationTrack.Length, as some animations can have it be zero. To fix this we have to manually update the animations to have nonzero length.)

Ideally I would like a property and signal which communicate when the animation is ready to start affecting CFrames, such as bool AnimationTrack.IsLoaded and RBXScriptSignal AnimationTrack.Loaded.

It would also be nice to have a way to just guarantee some animations to always be loaded, so that none of this is even a problem in the first place. It’s kind of a pain having to always handle animation asset loading stuff in our code - I want to be able to make the decision to have certain animations be reliably loaded in (just like you would get with KeyframeSequence instances in ReplicatedStorage). The same goes for sounds, images, other remote content - but that’s all a bit out of scope of this post.

7 Likes

Can’t you use ContentProvider:PreloadAsync?

Animations do not respect this method, animations cannot be preloaded via PreloadAsync…

1 Like

The post you linked appears to communicate the opposite point - that PreloadAsync can’t be relied upon to guarantee that things are loaded, instead it’s just a hint, and the assets in question could be evicted from the cache at any time.

Also, in practice you are just wrong. Sounds and images have a similar problem as well - they do not have an effect immediately, there’s always a small delay the first time they are used.

Additionally, I would also like a way to play animations without having to upload them.
Animation assets that are just embedded into the place itself, like physical objects you can just copy/paste or move around.

And I’m not referring to what Roblox animator uses to temporarily store and play animations “offline”.

I’d like to have an animation instance that is just always loaded and doesn’t have to fetch it’s keyframes from a different server where all Roblox assets are stored.