Pre-loading assets like lighting, ways to do with textures and meshes?

There are lots of sounds and animations within my game. Animations have a lot of KeyFrame triggers tied to them, so its important that they load quickly. And I really don’t want there to be any delay in sounds when the player starts interacting with the game.

In order to get around the initial loading “Delay” I’ve been using the following method;

function LoadMyAssets() --All this does is loads Sound and Animation. Currently no way of rushing Mesh/OBJ.

local Sounds = CLIENT.RepFirst:WaitForChild("Sounds")
local Animations = CLIENT.RepFirst:WaitForChild("Animations")
local AnimControl = Instance.new("AnimationController")
AnimControl.Parent = CLIENT.RepFirst

local MySound = CLIENT.SNDOBJ:Clone()
MySound.Parent = workspace
MySound.Volume = 0
for _, sound in pairs(Sounds:GetChildren()) do
MySound.SoundId = sound.SoundId
MySound:Play()
end
MySound:Stop()

for _, anim in pairs(Animations) do
local AnimLoad = AnimControl:LoadAnimation(anim)
AnimLoad:Destroy()
end

MySound:Destroy()
AnimControl:Destroy()
end

This basically ensures that when it comes to playing the sound or animation, the client has already loaded it, meaning the delay no-longer exists.

Is there any method that is similair to this for images and meshes at all? I keep having delays when new weapons are equipped where the texture/mesh still takes a few moments to load.
Many thanks!

Use PreloadAsync, I’m not sure if it works for meshes but it’ll work for sounds and images for sure.

http://wiki.roblox.com/index.php?title=API:Class/ContentProvider/PreloadAsync

2 Likes

If it doesn’t work for meshes, then a hacky way to do it is to place a transparent version of it into the game for a little bit. People used to do that with images by placing ImageLabels onto the screen briefly to load the images. Of course, don’t do this if you don’t have to.

2 Likes

Ah, no this method I’m using loads it waaaay faster than preloadasync.

You could use coroutines to lessen the visible impact of loading hundreds of assets :wink:

Do this at the start, theres a loading period. Its v fast.

What do you mean?

(FYI I was speaking in the context of PreloadAsync, not your function)

PreloadAsync is much faster than this and is the only way to solve your inquiry, I can assure you that. It also takes your code and flattens it down to a few lines without creating objects.

PreloadAsync preloads these assets for usage; the code provided merely plays and stops them at run time which is a relatively bad/inefficient practice - it could cause a frame spike depending on how many items are being pushed through for one.

To note, you should not be preloading your whole game; only the assets you need players to see or hear immediately upon initialization.

I only preload the things that would be noticable without being loaded.

Playing sounds is quite noticeable.

I know, thats why I load them :stuck_out_tongue:

use preloaaaaaaaaaaaaaaaaaaaaaadasynccccccccccccc

is more efficient + its better + less lines of code + quicker

And again, it’s the real only way to preload textures and meshes.

4 Likes