How to declare a generic delegate signature as a parameter Unreal/C++?

Well, one problem is that TSubClassOf * is a pointer to a UClass pointer. That isn’t what you want. You want a UObject*.

Second, the function ptr could be defined as simply: FInputActionHandlerWithKeySignature instead of the whole TFunction<void… thing.
To use that, you would call it with FInputActionHandlerWithKeySignature::CreateUObject(this, &SomeClass::SomeCallback).

Third, it looks like the bind functions you are using are not supposed to be used. Instead use the ones defined by DEFINE_BIND_ACTION:

DECLARE_DELEGATE(FEnhancedInputActionHandlerSignature);
DECLARE_DELEGATE_OneParam(FEnhancedInputActionHandlerValueSignature, const FInputActionValue&);
DECLARE_DELEGATE_OneParam(FEnhancedInputActionHandlerInstanceSignature, const FInputActionInstance&);	// Provides full access to value and timers

    DEFINE_BIND_ACTION(FEnhancedInputActionHandlerSignature);
	DEFINE_BIND_ACTION(FEnhancedInputActionHandlerValueSignature);
	DEFINE_BIND_ACTION(FEnhancedInputActionHandlerInstanceSignature);

Each DEFINE_BIND_ACTION unwraps into a function with this signature:

#define DEFINE_BIND_ACTION(HANDLER_SIG)
template<class UserClass, typename... VarTypes>
FEnhancedInputActionEventBinding& BindAction(const UInputAction* Action, ETriggerEvent TriggerEvent, UserClass* Object, typename HANDLER_SIG::template TMethodPtr< UserClass, VarTypes... > Func, VarTypes... Vars)

So, choose 1 of the 3 signatures in the DEFINE_BIND_ACTIONs, and use that defined delegate as your parameter, called with the aforementioned Delegate::CreateUObject (or other Create function you feel like using).

Let me know if that works/you have any questions. I have not tried compiling the code myself so I could be wrong.

1 Like