How to properly preload animations?

I’ve recently been looking into pre-loading my animations as they jolt when :Play() is fired. I’m not very sure of how should I go about doing this. Should I put all my animations in replicated storage or should I write a table in a local script to preload them. Is it also safe to preload the animations on the client?

One final question would be whether I should be preloading the animation track or preload the animation themselves?

2 Likes

This is done to save memory on the client. Why preload stuff that might not even be used? It saves both precious memory and less network usage.
To preload something (and only do this if it affects gameplay, as otherwise the track will only be “bugged” once) use PreloadAsync. As for what to load. I really don’t know, but I would say whatever you use :Play() on

tl;dr: it’s safe to preload them in a local script with a table, but not recommended unless the animations affect your gameplay.

1 Like

The animations are quite jittery which gives the player the feeling of an incomplete or uncoordinated animation. So, I guess I should preload it to give a complete feel to it?

I’m just slightly worried that loading the animations in a table on the client allows the client to change the animation to whatever they want which is not ideal.

Also, where are the animation tracks located at? Once I preloaded “loadanimation”, I want to access them from a server script.

Yes, any animation will play correctly and in time without delay as long the client have it downloaded (whenever it’s from PreloadAsync as AyeeAndrxw mentionned, or when you see the animation for the first time upon joining.

This will most likely never happens, common exploiters is just all about locals modification that benefits them (wall, speed, teleportation, game currency), you can make the animation play through the server if you’re spooked, though. :thinking:

Also small note : Animation assets is a exception as the game can only loads animation from the creator, simple example, you’ll never seen a Phantom Force asset loadable in your game, so the risk of anims exploited is much less than decal & audio.

Reason why you should use PreloadAsync is simply because it’s a preloader for assets, just take note that Animations is also a asset so you will have no issue preloading it. image

You normally don’t see the loaded asset as a “object” or the sort, but it’s pretty simple, just use the animation’s link, and if the asset is already downloaded (client side), then it will automatically regonize which file to play, a asset doesn’t download twice, even if you’ll try to make it download twice on purpose.

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://00000000" – Change to your asset url
local track = Player.Character.Humanoid:LoadAnimation(anim)
track:Play()

3 Likes

PreloadAsync doesn’t return anything. LoadAnimation returns an AnimationTrack object with a reference to the Animation object that was loaded. To be able to access them from a script, you’ll have to call load on the server or have the client pass the AnimationTrack to the server.

@kenami Ahh, so I can just preload the the load animation on the client then call the “load animation” again on the server to get the animation track?

@colbert2677 Would the above work too? Kenami says that if you’ve preloaded the load animation (AnimationTrack) on the client, then reloading the animation should allow the animation to be accessed.

My bad, I was writing pretty quickly and didn’t catch my error. I should have said “loaded” instead of preload.

1 Like

The act of preloading is prioritising the download of a Roblox asset in the queue so it can be used immediately. All Roblox assets must be downloaded first before they can be used and seen or heard in-game. Upon first usage of an asset, any related asset ids are queued for download and are displayed upon finishing. kenami’s post is completely viable.

You’ll see a slightly noticeable difference between preloaded assets and ones that aren’t. Once a client downloads an asset, it’s cached for the rest of the play session and can be used several times without any delay of missing textures or anything.

4 Likes

To put it on a simple way, if you play a Youtube video, while you plays it, it will automatically preload the rest of the video progressively, which is why switching video time would take less time loading than usual if your PC already have the video loaded,

Thought it also mean that your internet is consumed just like you fully downloaded the video (even if you don’t finish the video)

1 Like