# How to parallelize some actions in UE4?

**URL:** <https://forums.unrealengine.com/t/how-to-parallelize-some-actions-in-ue4/438028>\
**Category:** XR Development\
**Tags:** framerate, unreal-engine, question\
**Created:** [November 21, 2018, 9:05am UTC](https://forums.unrealengine.com/t/how-to-parallelize-some-actions-in-ue4/438028 "2018-11-21T09:05:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_a5e67abc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a5e67abc](https://forums.unrealengine.com/u/anonymous_user_a5e67abc)\
**Post date:** [November 21, 2018, 9:05am UTC](https://forums.unrealengine.com/t/how-to-parallelize-some-actions-in-ue4/438028/1 "2018-11-21T09:05:41Z")

</div>

Hi !

I am currently building a game in VR and some of the actions I have to perform require a bit of intensive computation. The problem is, predictably, when I click on the button launching computation, the engine becomes too busy, and Steam Chaperone takes over while the computation finishes too avoid freezes. (typically, I might have to display 3000 objects and on a clic of a button, a script computes the ideal position of each of them based on some criteria, script that is well optimized, but still computation intensive for high object number)

Is there a way to run the computation in parallel to the game, giving priority to the basic interactions, and display the results gradually as they are available ? (or all at once at the end if that doesn’t make the framerate drop). What I am looking for is some kind of a parallel processing maybe.

Thanks a lot !

PS: I use HTC Vive with Steam VR  
PPS: c++ or blueprints are both fine for me

---

<div class="post-metadata">

**Author:** ![Weibye](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Weibye](https://forums.unrealengine.com/u/Weibye)\
**Post date:** [November 21, 2018, 10:53am UTC](https://forums.unrealengine.com/t/how-to-parallelize-some-actions-in-ue4/438028/2 "2018-11-21T10:53:31Z")

</div>

Creating new threads that isn’t connected to the main game thread is what you are looking for. I have no personal experience with it yet and not sure if it is going to solve all your problems, but I can link some resources on the topic:

- [Multi-Threading: How to Create Threads in UE4](https://wiki.unrealengine.com/Multi-Threading:_How_to_Create_Threads_in_UE4)
- [MultiThreading and synchronization Guide](https://wiki.unrealengine.com/MultiThreading_and_synchronization_Guide)
- [Unreal Marketplace - Vega Threading](https://www.unrealengine.com/marketplace/vega-threading)
- [Implementing Multithreading in UE4](http://orfeasel.com/implementing-multithreading-in-ue4/)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a5e67abc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a5e67abc](https://forums.unrealengine.com/u/anonymous_user_a5e67abc)\
**Post date:** [November 21, 2018, 12:09pm UTC](https://forums.unrealengine.com/t/how-to-parallelize-some-actions-in-ue4/438028/3 "2018-11-21T12:09:00Z")

</div>

Thanks ! That looks like exactly what I needed. Going to give it a try !

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a5e67abc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a5e67abc](https://forums.unrealengine.com/u/anonymous_user_a5e67abc)\
**Post date:** [November 21, 2018, 3:55pm UTC](https://forums.unrealengine.com/t/how-to-parallelize-some-actions-in-ue4/438028/4 "2018-11-21T15:55:50Z")

</div>

Ok so I went ahead and implemented a few test functions. Most of it works.

However, I already have some quite complex blueprints in my project and it would be a pain to recreate all of them inside a c++ class. Any idea if there are some kind of a macro out there that would perform any action multi-threaded from blueprints ? (I found some Vega plugin but it is not supported anymore. )  
Also, I have read something about adding a simple delay of 0ms making the current execution asynchronous. This in turn suggests that it might then run on a separate thread. Do you know how this works ?

---

<div class="post-metadata">

**Author:** ![Weibye](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Weibye](https://forums.unrealengine.com/u/Weibye)\
**Post date:** [November 21, 2018, 4:14pm UTC](https://forums.unrealengine.com/t/how-to-parallelize-some-actions-in-ue4/438028/5 "2018-11-21T16:14:05Z")

</div>

I currently don’t have much knowledge on the topic. Multi-threading is something I know I have to learn down the line to solve some of our problems, but I haven’t had the time to dive into the deep end just yet.

I think (limited knowledge disclaimer) adding a delay in front of the function will make it asynchronous, but it will not be processed in a separate thread.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a5e67abc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a5e67abc](https://forums.unrealengine.com/u/anonymous_user_a5e67abc)\
**Post date:** [November 29, 2018, 3:45pm UTC](https://forums.unrealengine.com/t/how-to-parallelize-some-actions-in-ue4/438028/6 "2018-11-29T15:45:24Z")

</div>

The MultiThreqding and sync link ressembles more what I need since it allows thread safe data manipulation and return to the main thread.

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

Thx @Weibye for that 😉

It is still a bit unclear to me how to notify the main thread once the FRunnable is done computing but I have open a new post for this question here :

> **[How to notify the main game thread when the FRunnable is done?](https://forums.unrealengine.com/questions/853110/how-to-notify-the-main-game-thread-when-the-frunna.html)**
>
> Hi all ! I am making progress with multi-threading in ue4 but I am still a bit puzzled. How can I notify the main thread when my computation in the FRunnable is done so that I can they query the data from the thread (with a thread safe method ofc)...
