How to create a task in game thread and wait for it?

yy j
Fri, 19 Nov 2021 06:56:11 +0000
Plugins

In a plugin whose code is not on game thread, I want to use some functions from EditorAssetLibrary, which must be executed in game thread to work.

I tried the following code piece, but the whole engine GUI freezes. Seems that it is waiting for the task to complete foreverly.

FGraphEventRef Task = FFunctionGraphTask::CreateAndDispatchWhenReady([]()
{
    // Do something in game thread
    // Modify variable "Result"
}, TStatId(), nullptr, ENamedThreads::GameThread);

// Wait for the task
FTaskGraphInterface::Get().WaitUntilTaskCompletes(Task);

return Result;

3 posts - 3 participants