Scrap that, I get it.
From my worker’s DoWork() function:
FSimpleDelegateGraphTask::CreateAndDispatchWhenReady
(
FSimpleDelegateGraphTask::FDelegate::CreateStatic(&TestFunction,
m_loadedData),
TStatId(),
nullptr,
ENamedThreads::GameThread
);
Where TestFunction returns void and takes in a TArray<MyDataStruct> argument (which is m_loadedData in this case).
What I can’t figure out is how to pass in or bind a delegate from outside of here, i.e. binding/passing a delegate of my own choosing to this worker from outside of it, so that the worker doesn’t need a pointer to the object and the function in question (which could be several steps removed by this point).
I.e.
MyCoreClass::StartLoading ---- (Delegate bound to MyCoreClass::OnDataLoaded) ----> MyDataLoader::LoadData → MyWorkerInstance.BindDelegateSomehow(//use the passed-in delegate).
Then when MyWorkerInstance (of MyWorker type) finishes its DoWork, it invokes the delegate and passes the TArray<MyDataStruct> back to MyCoreClass::OnDataLoaded. You can see why requiring that I have a pointer to a MyCoreClass instance and know of its functions at the point of the DoWork function is a bit of a problem - I don’t want everything in this chain to have to know about everything else!
EDIT:
After digging, and even trying to create my own DelegateGraphTask class, it seems that the delegate used MUST be of the type given by DECLARE_DELEGATE(FMyDelegateName), yet it can take bindings from functions with one or more arguments? I thought you needed DECLARE_DELEGATE_OneParam(…) etc for that!
Is there at least a way to get my own delegate type (i.e. a OneParam) in where this type is currently? A way to copy the delegate binding across to this accepted type, or to swap out the delegate? I’d really not want to pass a pointer to the original object all the way down the callstack so that the delegate can be bound at the point of task creation. And having my public delegate type be DECLARE_DELEGATE gives users of my code no real indication of the format needed for whatever functions they choose to bind.
EDIT#2: I’m an idiot.
The solution to the above was just to execute the passed-in/bound delegate inside the function that I’m binding to the above task. I.e. the OnDataLoaded calls my delegate and passes the worker’s output through. All is well/solved