Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there an efficient way to preload multiple Animations?

Asked by 6 years ago

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!

0
Load the animation on Dummy's? User#19524 175 — 6y
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 Vulkarin 581 — 6y

1 answer

Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago
-- 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

0
Can you remove animations tracks if they are not playing, but still loaded into the character? Not that I need to just curious. FrogNinjaX 222 — 6y
0
Yes hellmatic 1523 — 6y
Ad

Answer this question