I’m having trouble with binding a pointer to a function with a specific signature to a delegate with the same signature.
There is an existing delegate, declared like DECLARE_DELEGATE_TwoParams(DelegateName, VarType1, VarType2)
. It is already correctly called when necessary, I just can’t bind a function to it.
I need to bind a function declared like void Function(VarType1, VarType2)
to it. The function is not a member of the class that is has the delegate and is doing the binding, it comes from another class. So I cannot access it directly in a &Class::Function
way, like most examples I’ve been able to find.
Rather, the function has to be a variable, which I assume is a function pointer like void(*CallbackFunction)(VarType1, VarType2)
, or a TFunction like TFunction<void(VarType1, VarType2)> CallbackFunction
.
What should the input variable type be for the function I’m trying to bind, and what is the syntax and the correct bind function ( BindSP
/ BindRaw
/ BindUObject
etc) to make this work? I assume the function should look roughly like:
static void GenericBinder(UObject* CallingObject, TFunction<void(VarType1, VarType2)> CallbackFunction)
{
// get delegate, store in var called DelegateToBindTo
DelegateToBindTo.BindRaw(CallingObject, &CallbackFunction);
}
Anything similar that I’ve tried gives me massive compilation errors. What am I doing wrong? Many thanks in advance.