How to bind a function pointer (void* or TFunction) to delegate (non-dynamic non-multicast) in C++?

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).

I need to be able to bind a function declared like void Function(VarType1, VarType2) to it. The function is not a member of the class that is doing the binding, 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.

Hello! You can just add function declaration in some .h file, include it in CPP where you want to bind delegate and just use global resolve operator ::