How do I Display a Progress Bar While Game Loads a Task With Zero FPS?

There’s a part of my game that sends the FPS straight to zero, and takes about 30 seconds to load. I want to be able to display a progress bar while it loads. I heard about FSlowTask, and I was able to get it to work in the editor, but I haven’t been able to get it to work inside of a packaged project. Is there a way for me to display a progress bar while my game loads that is compatible with a packaged project?

Yes, but you’ll need to use a little C++ or get a plugin that will do an async task. If you’re willing to go for C++, look into

public FRunnable, public FSingleThreadRunnable

I know basically no C++, but I want to get a better understanding of how FRunnable and FSingleThreadRunnable work. Could you explain a little bit about how they are able to update a graphical object even when FPS is zero? Would they be able to work with an SProgressBar?

Well, it’s a pretty complicated system so if you’re not adept with C++ I’d return to the plugin suggestion, but essentially you’ll create a thread that updates on a set interval and on that interval you’ll run a function. That will do your work and update a double variable somewhere else based on how much work was completed, like a percentage. Then on the Slate thread you’d update the progress bar based on the double variable I was just talking about. It’s not too dissimilar to how you use FSlowTask in the editor.

You also may be able to get something like this working with a timer. Like SetTimer>OnTimerFunctionCalled>DoWork>UpdateProgressBar. This isn’t a separate thread, it’s on the main thread so it would be slower than a true threading operation but it’s a lot easier to implement. It really depends on the nature of the work being done. What is being done when your FPS drops?

Well, it’s a pretty complicated system so if you’re not adept with C++ I’d return to the plugin suggestion

I see that you have a ‘Marketplace Creator’ tag. Do you know of any plugins that could handle this? Or, would you be willing to make one for me? I only need basic functionality.

What is being done when your FPS drops?

I’m trying to embed one of those newfangled diffusion models into Unreal Engine. Diffusion models use a ton of VRAM to load the models, so FPS ends up getting sent straight to the shadow realm. I asked another question on this forum earlier this week about if it would be possible to temporarily offload Unreal’s VRAM while the model runs to speed up load times, but I didn’t get any responses. You wouldn’t happen to know if that would be possible, would you?

There are a few marketplace options:

Generally you can only thread things that can be done with a loop, so keep in mind if you’re calling a single function, set it and forget it kind of thing, you’re not likely to see any benefits.

As far as memory in blueprints, there isn’t any direct memory management. Basically, you destroy or orphan objects and let garbage collection handle the rest. In C++, you can leverage the heap and explicitly delete objects in memory. It really depends on your use case and what libraries you’re using.

Thanks for the recommendations. I am using a for loop, so there shouldn’t be any problems there. Just to be clear, does the heap work with VRAM, or strictly regular memory? Also, if I were to explicitly delete all objects in VRAM, would that cause any issues like the game crashing or the screen going black since there would be nothing in VRAM to show?

VRAM uses its own heap which is different from regular RAM, yes. How you access it is going to depend on what graphics API your end users will be using. For compatibility reasons it may be best to use Vulkan or OpenGL unless DX12 or Metal have specific libraries or objects you need to access.

Deleting memory you created from VRAM is not likely to cause any issues of that nature since you’re not writing the graphics pipeline here, you’re only heaping and deleting stuff for your model. Making an API call to delete all VRAM is going to cause issues though, yes. Likely a stall and then a crash. There aren’t any real safeguards in place when working on the heap, so be careful!

Ok, thank you for all the help.

1 Like

There are different solutions depending on what you’re doing. Are you loading in a level?
You can load it in asynchronously as an instance into the current persistent level with the Load Level Instance BP node, or by using ULevelStreamingDynamic in C++.
image

If you need to do a full level switch, you can still start loading it in the background asynchronously before triggering the switch to it using the Async Load Asset BP node and feeding it a soft pointer to the map. This should make it a lot faster and won’t require a full flush of the async loader.
image

If you are not loading a level or some assets, but just doing a lot of computation in your own code, then you should take advantage of the Tasks System. That’s the new preferred way of doing threads in Unreal.

Hey Ari, I mentioned earlier in the thread that I’m trying to embed a diffusion model into Unreal. Diffusion models typically use a lot of VRAM and take a while to compute which is what is causing this sustained lag.

@JaredTherriault provided me with a list of plugins that may be able to help with this. I tried reaching out to one of the plugin creators to see if their plugin could help me, but they said it would be impossible 'because the thread tick of this plugin is synchronized with the main thread tick in time'. They also mentioned that 'ue's ui rendering is also a separate thread and related to the tick execution of the whole game'.

Would the task system be capable of visually updating a graphical object? Would the limited VRAM pose issues to this? Also, what is the minimum version of Unreal that supports the task system? I’m currently working in 5.0.3.

Ah I missed that!

You shouldn’t update graphical objects in other threads generally, that’s best to do in the game thread. But what you can do is that you can have a shared object with atomic variables that the game thread queries to update graphics for. Or if you have more complicated graphics to show you should have your thread sync off tasks to the game thread when it has something to show for the smoothest results.

I’m not sure how to do that in the Task System but through the Task Graph you would do it like this:

// Do stuff in your thread.

FMyData CopyOfYourData = FMyData (DataThatWillKeepChangingInThisThread);

AsyncTask( ENamedThreads::GameThread, [CopyOfYourData]()
{
	// Anything put in here will happen during the next tick of the game thread
	MyUIManager->UpdateUI(CopyOfYourData);
});

Do you know of any plugins that could help me do this? I’m relatively new to Unreal and I don’t know much C++.