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:
- Not documented or officially supported
- We have to poll the properties we care about (there are no signals)
- 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.