PreloadAsync is not actually preloading images

I am using PreoadAsync on ReplicatedStorage to make sure some ImageLabels are preloaded. What I am doing is making some 'anime style speed lines" in the GUI.

Here is the code that runs the speed lines:

        spawn(function()

            local stepsPerSecond = 10

            -- seconds
            for count_A = 1, mudaDuration do

                -- steps per second
                for count_B = 1, stepsPerSecond do
                    local thisFrame = mudaGui.SpeedLines:FindFirstChild(math.random(1, 10))
                    thisFrame.Visible = true
                    wait(1 / stepsPerSecond)
                    thisFrame.Visible = false
                end

            end

            mudaGui:Destroy()
        
        end)

when they player joins, I am doing this:

    spawn(function()
        wait(10)
        game:GetService('ContentProvider'):PreloadAsync({workspace,game:GetService('ReplicatedStorage'),game:GetService('PlayerGui')}, function() print("Content Preloaded") end)
    end)

When I run the speedlines function in the game for a player for the first time, it has not actually loaded in some of the images yet. As you an see in the code above, its picking an image at random and sometimes the one picked wont be loaded.

In the video below, as it goes through this process eventually it will load them all and you will see the animation is smoother without missing frames.

After we run it once for the player, now all images are loaded. This is what it should look like, the speedlines are all present and theres no flashing.

How can I truly make sure these images are loaded so the first time it runs will be good?

Content doesn’t preload in studio, try it in the actual game

Same issue, the first time we play it in-game its missing some frames that havent loaded yet. Second time it works fine.

Gotcha. I think it might be because you should be loading the content (like the link) instead of the image label instance, have you tried that?

Probably the most egregious problem is that you’re trying to preload entire services which is virtually the same as preloading nothing. That’d be even moreso the case if you preloaded more than just this.

Keep in mind that the only purpose of PreloadAsync is to prioritise which assets should be downloaded from the CDN first. It doesn’t actually guarantee that the assets you pass will be downloaded and ready for use before the client spawns in. It needs to be used sparingly.

PreloadAsync should only ever be used on assets you need seen immediately, such as loading and menu screens. You will have to let the rest stream in as players play. Download times will also vary between each client based on factors such as their internet connection.

3 Likes

That’s all well and good, the code was setup as a way to force things while in testing. I will switch this up to preloading exactly what needed instead.

Thats said, I have let the client sit for 10 minutes after loading in and this problem persists, the images aren’t there ready to be displayed until they play at least once first.

Huh, interesting. Perhaps you may want to create offscreen ImageLabels with the loaded asset id and then delete them all shortly after in order to force them to load once. PreloadAsync should make the asset immediately available but if it’s not until it’s shown once then you may want to consider forcing it to render, albeit offscreen, once before removing it perhaps.

1 Like

Was hoping not to do that, thats quite a bit of overhead and code complexity for one little thing. I have dozens of small cases like this, all of them different.

This surely should be solvable, why cant roblox -just preload an asset when i ask it to, I wonder? Must we only rely on “just in time” loading?

hrmmmm

2 Likes