This part confuses me, if you already have the dynamic delegate bound in blueprint and passed to your function why would you need to bind it again in C++? Or do you just want to change the binding of the given delegate?
Otherwise I would have suggested you use a non-dynamic delegate internally and either use .GetUObject
and .GetFunctionName
along BindUObject
as @zeaf already meantiond or simply wrap/capture the dynamic delegate in a lambda and use BindLambda
on the non-dynamic delegate.
The BindDynamic macro has one very important functionality and that’s converting the argument to a string using #
in TEXT( #FuncName )
. So if you pass the function pointer directly to the macro it passes the string "&UMyObject::ActOnSomeDelegate"
to GetTrimmedMemberFunctionName
. But if you wrap that in another function as an argument InFunc
you lose that information and the string passed to GetTrimmedMemberFunctionName
would just become "InFunc"
which is obviously not what we want.
If you’re willing to change your parameter to UFunction *
instead and use FindFunction
/FindFunctionChecked
wherever you call it you can get the name from the UFunction
(but you already need to know the name to find it in the first place).
Another alternative would be to replace the function ListenForRoutedInputAction
with a macro as well.