AnimationTrack.Loaded, AnimationTrack.IsLoaded

As a Roblox developer, it is currently too hard to accurately yield for an Animation to load in without using a hacky approach or polling until AnimationTrack.Length is above zero.

If Roblox is able to address this issue, it would improve my development experience because then I could make sure that my animations are fully loaded before doing an operation such as the one shown below.

AnimationTrack:AdjustSpeed(AnimationTrack.Length / Humanoid.WalkSpeed)

Use-case/Scenario

I was creating a script to handle my mob’s animations which had their speed adjusted depending on the current Length value, accounting the mob’s WalkSpeed. I was surprised to see that none of the following methods below worked.

The following yielded forever:

AnimationTrack:GetPropertyChangedSignal("Length"):Wait()

if AnimationTrack.Length > 0 then
    -- Do stuff
end
while true do
    AnimationTrack.Changed:Wait()
    
    if AnimationTrack.Length > 0 then
        break
    end
end

The following barely yielded and still returned 0, showing it didn’t actually do anything.

ContentProvider:PreloadAsync({AnimationTrack})

The only way to currently do this from what I’ve noticed is to poll until Loaded doesn’t equal 0 which is unnecessary when there could be a native event-based approach built into the AnimationTrack instance, like we have for Sounds (bool Sound.IsLoaded and event Sound.Loaded).

32 Likes

Absolutely, I’m struggling with determining if animations are loaded in my game just now. It’s very awkward because I need the keyframes to exist, and having to use a wait() feels awful.

3 Likes

You might want to title your thread after the problem, rather than the proposed solution (API signatures).

Ref: How to post a Feature Request

1 Like

This is still very relevant. I’ve been fighting a bug for over three months and it’s solely because there’s no real way to determine if an AnimationTrack is loaded or otherwise.

I have code that waits for an AnimationTrack’s length to be greater than zero before it returns the animation. Most cases, this is really all I need. An AnimationTrack’s length will be zero until it’s loaded. However, the bug lies in animations that have one keyframe at time zero - now the AnimationTrack length is zero both when it’s loaded and not loaded. This bug was so tough to figure out that it ended up making me step away from my game for over three months with occasional check-ins to see if I could solve the problem.

The solution isn’t “just make your animation longer,” for I shouldn’t need to make workarounds to implement something that should be an innate feature.

I think that a new base class is implemented that reflects all media items would be neat. This means that Decals, AnimationTracks, Videos, ImageLabels, ImageButtons, Textures and Sounds (+ more) would inherit from this class, and this base class holds .Loaded, :IsLoaded, and their AssetId. That would be exceptional.

9 Likes

Bump bump bump.

The only way, as said by the requester, is polling the property AnimationTrack.Length, since a change in the Length property (uppon loading) does not trigger any event, so AnimationTrack:GetPropertyChangedSignal(“Length”) or AnimationTrack.Changed never fires for this property.

I needed to know when an animation has loaded in order to get the time of some keyframes using the method AnimationTrack:GetTimeOfKeyframe, but calling this before the animation has loaded errors with the message “Invalid operation for this animation format.”.

7 Likes

Bump!
I need to know a way to know if the animation track successfully loads or not.
I have a script that listens to an event in the animation track, but if it fails to load, the event will never be reached and my script will be stuck waiting for the event.

I was surprised that there is no good way to see if an animation track has loaded.

Another method I’ve seen is waiting until AnimationTrack.Length > 0, though that might have the same problem as waiting for a marker to be reached.

Please add this, right now theres no way to know if an animation loaded in we have to resort to hacky methods.

Or make it so that ContentProvider:PreloadAsync({AnimationTrack}) works.

1 Like