Your comments helped and I got it to compile by making it templated method:
template<class UserClass>
inline void BindThrottleAction(UInputComponent* PlayerInputComponent, UserClass* Reciever, FEnhancedInputActionHandlerValueSignature::TMethodPtr<UserClass> Signature)
{
UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(PlayerInputComponent);
if (!ensure(!(EnhancedInputComponent == nullptr))) return;
if (!ensure(!ThrottleAction)) return;
EnhancedInputComponent->BindAction(ThrottleAction, ETriggerEvent::Triggered, Reciever, Signature);
EnhancedInputComponent->BindAction(ThrottleAction, ETriggerEvent::Completed, Reciever, Signature);
}
And the caller calls it like so:
InputWrapper->BindThrottleAction(PlayerInputComponent, this, &SomePlayerPawn::UpdateThrottle);
But I’m not getting the
SomePlayerPawn::UpdateThrottle
callback to execute. I think the issue has something to do with referencing the class properties in the template method. I think it’s failing thoseensure
calls, (or it’s just hanging).~I then tried to have the template call a private method that then performed the actual work, declared as follows:
void PrivateBindThrottleAction(UInputComponent* PlayerInputComponent, void* Reciever, FEnhancedInputActionHandlerValueSignature* Signature)
And passing using your recommended
FInputActionHandlerWithKeySignature::CreateUObject()
. That works perfectly for the signature, BUT the compiler couldn’t resolve passingvoid *
toBindAction()
.I then thought of getting a
UClass
object of the UserClass object and casting thevoid *
using the UClass object. But that doesn’t seem supported.At this point I’m going to just do something more simple. I think this is too in the C++ weeds for me.
Thanks for the help though! I’d be interested if there were a way to do this.
EDIT: I was wrong. The template was working perfectly fine! I had this ensure backward: if (!ensure(!ThrottleAction)) return;
Thanks for the help!