How to pass non-UFunction as parameter?


How to define a function parameter, so I can pass another function with it?

I’m trying to create a function template that will take another function (but not UFUNCTION) as parameter, like in BindUObject:

Delegate.BindUObject(this, &AMyTestActor::MyTestFunction);

I tried to simply recreate the way it’s done in BindUObject:

template <typename UserClass, typename... VarTypes>
inline void BindUObject(UserClass* InUserObject, typename TMemFunPtrType<false, UserClass, RetValType (ParamTypes..., VarTypes...)>::Type InFunc, VarTypes... Vars)

but this gives me “no instance of overloaded function matches the argument list” compile error when I try to pass another function in my function.

Hi! There are several things that can help you

OK, I managed to do this like that:

template <typename UserClass, typename... VarTypes>
static void MyFunction(UserClass* WorldContextObject, typename TMemFunPtrType<false, UserClass, void(VarTypes...)>::Type InFunc, VarTypes... Vars)
    FDelegate MyDelegate;
    MyDelegate.BindUObject(WorldContextObject, InFunc, Vars...);

The only restriction is the parameter function InFunc must have return type void (or other predefined type), but void is enough for me.

Thanks, I ended up using TMemFunPtrType.