Even with FCriticalSelection locks I'm getting data race errors. Any suggestions?

This is a very good catch. Thank you. I think I may have found my data race issue. I didn’t have “void AAsyncPatherfinderActor::NotifyPathfindingCompleted(const FString& UnitID)” Tied to the same lock as the Thread pool logic.

I added:

void AAsyncPatherfinderActor::NotifyPathfindingCompleted(const FString& UnitID)
{
FScopeLock Lock(&NotifyPathfindingCompletedCriticalSection);
OnPathfindingCompleted.Broadcast(UnitID);
ActiveTasks.Decrement();
}

and then I also created another lock with these two to prevent my blueprint from accessing them too fast.

FUnitPathsCPP AAsyncPatherfinderActor::GetNextQueueItem()
{
FUnitPathsCPP queueitem;
FScopeLock Lock(&AsyncPathfinderQueueCriticalSection);
AsyncPathfinderQueue.Dequeue(queueitem);
return queueitem;
}

bool AAsyncPatherfinderActor::IsQueueEmpty()
{
FScopeLock Lock(&AsyncPathfinderQueueCriticalSection);
return AsyncPathfinderQueue.IsEmpty();
}

I just pushed it waaaay beyond the speeds my game will use and it didnt crash after 10 minutes.

What are your thoughts on having my pathfinding pool 8 threads? Too aggressive?