Or you could just push it onto the TaskGraph and mention in the Task that it’s only supposed to run on the game thread.
See [FONT=Courier New]TaskGraphInterfaces.h and the comment on line 498-ish:
The user defined task type can take arguments to a constructor. These arguments (unfortunately) must not be references.
The API required of TTask:
FGenericTask(TSomeType InSomeArgument) // CAUTION!: Must not use references in the constructor args; use pointers instead if you need by reference
// Usually the constructor doesn't do anything except save the arguments for use in DoWork or GetDesiredThread.
// you will be destroyed immediately after you execute. Might as well do cleanup in DoWork, but you could also use a destructor.
FORCEINLINE TStatId GetStatId() const
[static] ENamedThreads::Type GetDesiredThread()
return ENamedThreads::[named thread or AnyThread];
void DoTask(ENamedThreads::Type CurrentThread, const FGraphEventRef& MyCompletionGraphEvent)
// The arguments are useful for setting up other tasks.
// Do work here, probably using SomeArgument.
As mentioned bad things happen if you create actors on any other thread