I’m working on some things that require millions of traces and for that I need to use multithreading.
The problem is that I need to have a function that is not blocking Game Thread, but is using all other logical threads like ParrarelFor. Do you know how I could achieve that?
Because I can use FRunnable which will be async, but it’s slow as it’s on just 1 logic thread. ParrarelFor is much quicker, but it’s blocking also GameThread. Is there something in between? Or maybe I can somehow prevent ParrarelFor from running on GameThread?
FRunnable can’t receive UObjects, it can only be used to do mathematical calculations, what you want is to use AsyncTask, this will run your function asyncronously on the game thread, it will not block the game thread, to a certain limit, i used it to spawn 9000 instanced meshes seamlessly with no lag spike.
use FRunnable for calculations, and AsyncTask to manipulate a large amount of actors (or line traces) in the game world.
here is where you can learn it:
Thanks for your answer. We indeed used an AsyncTask, but it wasn’t enough. Because normally AsyncTask uses 1 worker thread and our calculations were too heavy to use just one thread.
What we used was ParallelForWithExistingTaskContext inside an AsyncTask and thanks to that we could limit used worker threads for example to 1/2 of all available logic threads. So it’s not blocking game thread and it’s much faster.