How can my custom thread notify calling object of completion?

My character class calls

TArray<FVector>* vertP;
TArray<FRuntimeMeshVertexNoPositionHiPrecisionNormals>* dataP;
icoSahedron->rtm_Base->BeginMeshSectionUpdate(0, vertP, dataP);
FProcMeshRunner::runInit(icoSahedron->listVerts, icoSahedron->mSub, basePOSs, baseData, inName, inSubLvl, inNoise);

BeginMeshSectionUpdate provides references to the vertex array pointer, and vertex data array pointer. FProcMeshRunner::runInit() starts the thread up and works out the new vertex information. Now at this point, until the work is done the vertices are never submitted to the GPU through the call

icoSahedron->rtm_Base->EndMeshSectionUpdate()

I’m still learning this all but I believe that call needs to occur from within the Character class, but how does the character class know that the thread finished? I can’t call a character class method from the thread class because of circular dependency, and it seems extreme to have a tick function monitor the thread class with a IsFinished() method locally. I would imagine the best thing would be for the thread class to notify the character class so the character class can call icoSahedron->rtm_Base->EndMeshSectionUpdate().

Actually using either Tick or a timer on your main thread is what you want to do. In my case I had a thread that was called by the game state and would constantly update as long as the match was in session so I create a variable

bool threadFinished;

Then in the thread I created a reference to that variable

bool *threadFinished

When starting that thread I pass that variable to the singleton.

MyThread::Init(&threadFinished, &data);

On my thread when the work is done, I set the threadFinished reference to true and it sets it on the game thread (since you passed a reference to it)

This polling approach is what I used and it cut my Game thread time in half.

But that means you have to monitor that bool value on your game thread right? Is there a way I can pass a function like I would a bool reference? I get that monitoring that bool value could be done in a smaller way like only calling the monitor function a couple times a second, but wouldn’t it be nice to just have the work thread, when finished, call a function on the game thread to say it is done? Is this not possible, if the work thread calls a function on the game thread object that originally called for the creation of the work thread, does this function call stem from the work thread or the game thread?

You don’t want to call any function on UObjects from threads. They are not thread safe. So that’s a bit risky. I’ve not had any consistent success with it and everyone I talk to says it’s a bad idea unless you are extremely careful.

In my case, running a single if statement in my game state had minimal impact on my game thread and perusing a even more efficient method wasn’t really worth it. If you think the effort associated with finding a more efficient method is worth it for you (perhaps there are so many instances of this threaded object that using Tick is off the table) then I encourage you to do so. I just haven’t found that case to be the case myself.