# Returning values from another thread

**URL:** <https://forums.unrealengine.com/t/returning-values-from-another-thread/292025>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [August 25, 2014, 11:24pm UTC](https://forums.unrealengine.com/t/returning-values-from-another-thread/292025 "2014-08-25T23:24:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_3115d24a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3115d24a](https://forums.unrealengine.com/u/anonymous_user_3115d24a)\
**Post date:** [August 25, 2014, 11:24pm UTC](https://forums.unrealengine.com/t/returning-values-from-another-thread/292025/1 "2014-08-25T23:24:01Z")

</div>

Basically I am trying to make a function that takes parameters on another thread because it is relatively expensive, then **return an output value to the game thread** I found Rama’s wiki thread very helpful ([A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums](https://wiki.unrealengine.com/Multi-Threading:_How_to_Create_Threads_in_UE4)) but it did not cover how to get the values calculated back to the game thread.

How would I go about this?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3115d24a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3115d24a](https://forums.unrealengine.com/u/anonymous_user_3115d24a)\
**Post date:** [August 27, 2014, 11:54pm UTC](https://forums.unrealengine.com/t/returning-values-from-another-thread/292025/2 "2014-08-27T23:54:49Z")

</div>

Anybody? I really need help on this!

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [August 28, 2014, 7:07pm UTC](https://forums.unrealengine.com/t/returning-values-from-another-thread/292025/3 "2014-08-28T19:07:56Z")

</div>

If you look at this section of my tutorial

> **[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 — ue4community.wiki! You will be able to find content from the official...

The TArray is actually stored in the pc class, just avoid accessing it in the game thread until the other thread has finished filling it!

and never use ranged for loops when doing fancy stuff like this, use the standard for loop, so you check the length each time 🙂

Rama

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3115d24a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3115d24a](https://forums.unrealengine.com/u/anonymous_user_3115d24a)\
**Post date:** [August 29, 2014, 12:53pm UTC](https://forums.unrealengine.com/t/returning-values-from-another-thread/292025/4 "2014-08-29T12:53:48Z")

</div>

Sorry silly question, but I am new to all this. Because the thread variable is private, I can’t use the Thread-\>EnsureCompletion() (or whatever it is) to make sure that the thread has finished In the PC class. How should I go about knowing weather or not the thread is done?

---

<div class="post-metadata">

**Author:** ![silentkratos](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@silentkratos](https://forums.unrealengine.com/u/silentkratos)\
**Post date:** [March 7, 2015, 10:33am UTC](https://forums.unrealengine.com/t/returning-values-from-another-thread/292025/5 "2015-03-07T10:33:22Z")

</div>

How did you get it working? Can I see your code?
