3D Perlin noise and Multi-Threading?

Hello Unreal Community,
I’m fairly new to programming in UE4 and I wanted to make a voxel terrain generation, similar to minecraft.
I got it working using the C++ 2D and 3D Perlin Noise functions, but everytime I get in a new unloaded chunk the game freezes until the generation is done.
I read about Multi-Threading (https://www.orfeasel.com/implementin…eading-in-ue4/) and I also got this working to calculate prime numbers, just like in the tutorial.
Now my question is, how can I use Multi-Threading to generate a terrain? Because according to multiple forums and websites I shouldn’t neither create nor destroy AActors in another task/thread. My first guess is that I need a return value from the Multi-Threaded function, but at the second thought that doesn’t make sense because the rest of the program needs to wait for the return value… or does it?
Or can I call from the Multi-Threaded function a function back in the Main-Thread?
I hope I could explain what my problem is. Thank you

The main thread has to check the thread function, you can’t “call back” into the main thread. So you can either use something like a Future and just check if the future is valid yet (i.e., your stuff was done running) and then grab those values. But, yea you either have to have the main thread wait, or just check next frame if the work is done yet then process it. Ideally the later.

Thank you for your help. And I’m sorry but I can’t get it working. I found this forum thread (https://forums.unrealengine.com/deve…branch-and-4-8) but I don’t get it working… I literally copy pasted from that forum thread but it doesn’t know the Future template (I didn’t forget to include the header file), but it knows TFuture. But then I get an error from the Async template, no instance of function template matches the argument list.

The code looks like this:


int AWorldGenerator::CalculateA() {
return 25;
}

TFuture<int> A = Async<int>(EAsyncExecution::Thread, CalculateA);

What am I doing wrong?