Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there an efficient way to preload multiple Animations?

I am creating a game which naturally has a lot of assets. Because of this lower end computers might lag and consequently when they play an animation I have binded to a key with ContextActionService, it may be quite delayed.

In order to fix this I was thinking of preloading all of the animations at the start just by loading them all into the humanoid right off the bat instead of loading the specific animation into their humanoid after they press the designated key. But I was worried that loading a lot of animations into the humanoid like that may just make the lag worse?

I'm not quite sure what stress animation loading puts on the client and if loading a lot of animations will have any serious negative effects. The only help I could find about this was the ContentProvider/Preload function which has evidently depreciated.

Could I get some tips on how to handle this? Thanks!

2 comments

0

Load the animation on Dummy's?

0

I don't think it will make the lag worse, if you really need to you could have one of those silly loading screens while everything preloads

1 answer

✓ Accepted answer
-- REMEMBER THAT ANIMATIONS DON'T NEED REMOTES IF FE IS ON (when you play the animation, it will play for ALL clients automatically without a remote)

local ContentProvider = game:GetService('ContentProvider')

local Humanoid = game.Players.LocalPlayer.Humanoid

local Animation = Instance.new('Animation')
local AnimationTrack = nil 

function PreloadAsync(asset)
	ContentProvider:PreloadAsync(asset)
end

-- after setting the Animation id preload it before playing the track: PreloadAsync({Animation})

Animation.AnimationId = 9999
PreloadAsync:({Animation}) -- always have to be in arrays {}

AnimationTrack = Humanoid:LoadAnimation(Animation)

AnimationTrack:Play()

-- You can remove animation tracks like this:

AnimationTrack.Name = "CUSTOM"

function STOP_TRACKS()
	local Tracks = Humanoid:GetPlayingAnimationTracks()
	for _, v in pairs(Tracks) do 
		if v.Name == 'CUSTOM' then 
			v:Stop()
			v:Destroy()
		end
	end
end

2 comments

0

Can you remove animations tracks if they are not playing, but still loaded into the character? Not that I need to just curious.

0

Yes

This discussion is preserved as it was. New answers, comments, and votes are closed.