I am fairly new to c++ programming, and I have a function that generates triangles to be used with a procedural mesh component, but I want it to be run as an async task. I am aware that you cannot edit values, or create new mesh sections in an async task, so I just want to call the async task, return the tris, and generate the mesh on the main thread.
How would I implement returning values from an async task that is executed from “begin play”?
Thanks,
Will
Edit: I’ve googled a lot and read the documentation, something about using a delegate as an async task parameter? I am very confused please help!
TFuture<TArray<MyTriangles>> TriangleFuture;
TriangleFuture = Async(EAsyncExecution::TaskGraph, MyDelegate);
// Later...
if(TriangleFuture.IsReady())
{
// Process your triangles.
}
else
{
// Try again next frame or wait.
}
This gives me an error on the Async(EAsyncExecution::TaskGraph, chunkDel) part, I don’t know why.
no instance of function template “Async” matches the argument list
TUniqueFunction<TArray<FXYZ,FDefaultAllocator> (void)>::TUniqueFunction(const TUniqueFunction<TArray<FXYZ,FDefaultAllocator> (void)> &)’: attempting to reference a deleted function
Code:
TUniqueFunction<TArray<FXYZ>()> Task = [this, x, y, z, scalarField]()
{
TArray<FXYZ> triArray = InitChunk(x, y, z, 0.5, scalarField, scale);
return triArray;
};
Result = Async(EAsyncExecution::Thread, Task);