How do I set up Multi-threading?
I was looking for a way to multi-thread so my world generation could continue during runtime, but I cant find a single thing on multi-threading in UE4 anywhere. Can someone point me where to look or give me some tips on how to do it?
You probably want to check out FRunnable and FRunnableThread. FRunnable encapsulates a worker that does the actual work. You inherit from this class, then implement the Run() method (and possibly others, such as Init(), Stop() and Exit()). You can then create a thread that uses this worker with FRunnableThread::Create(). You should be able to find many examples in the code base.
We have some other multi-threading mechanisms in the Engine, but your use case may not be a good fit. If your units of work are very small, you can take a look at the Task Graph system, which provides a nice way of performing task based multi-threading, and which is particularly useful if your tasks have dependencies to each other. You can find some usage examples by searching for CreateTask() in the code base.
Please note that the UObject sub-system is currently not thread-safe, so depending on what you're trying to do for world generation, you have to be extremely careful and know what you're doing :)
answered Apr 21 '14 at 05:51 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here