AnimationTracks questions

Hello everyone, i have some performance related questions about animation tracks.

if you use :LoadAnimation() twice with the same animation, does that make two of the same animations, or, does it only load it once and then recall it on the second turn?

the reason i ask is because animationtracks take a little bit to load, and its very obvious during the first use, making the game seem laggy. therefore, i had the idea of loading all of the animationtracks as soon as a player joins, then call all of them with no latency as far as initial loading.

or, would loading that many tracks (for a combat game) be a terrible idea considering the amount loaded at once? would that be even worse?

thank you for your time.

Looks like calling Animator:LoadAnimation() with the same Animation as argument does not return the same AnimationTrack. This is probably the case because AnimationTracks have a few properties that can be changed after being loaded (ex. AnimationTrack.Looped can be changed during runtime to change whether or not the animation will loop after :Play() is called).

To test caching behavior of LoadAnimation
local animationToLoad: Animation = PATH_TO_ANIMATION
local animator: Animator = PATH_TO_ANIMATOR

local animTrack1: AnimationTrack = animator:LoadAnimation(animationToLoad)
local animTrack2: AnimationTrack = animator:LoadAnimation(animationToLoad)
print(animTrack1 == animTrack2) --> false

It would definitely be wise to “initialize” AnimationTracks, implementing a custom system of caching behavior where possible as loading duplicate animations would lead to higher CPU and memory usage. If you’re making a combat game, you would likely want to load all animations available to a particular character’s move set on character spawn - that way AnimationTracks are readily available and you could avoid having to worry about whether an AnimationTrack is already loaded or not. Be sure to keep in mind difference between loading an Animation on the server vs. client.

1 Like

This seems like a good piece of advice. thank you!