I’m trying to create a wrapper object that sets up enhanced action bindings by basically wrapping UEnhancedInputComponent::BindAction()
, however I’m having a hard time declaring the wrapper method parameter so that BindAction()
accepts it.
Basically I want to define my wrapper like so:
void InputWrapper::BindThrottleAction
( UPlayerInputComponent* PlayerInputComponent,
TSubclassOf<UObject> *Receiver,
TFunction<void(const struct FInputActionValue& Value)> &UpdateThrottleSignatureAddr
)
{
// This fails to compile
Cast<UEnhancedInputComponent>(PlayerInputComponent)->BindAction(ThrottleAction, ETriggerEvent::Triggered, Receiver, UpdateThrottleSignatureAddr);
}
And then the PlayerPawn calls the following in SetupPlayerInputComponent
void ASomePlayerPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
//...
InputWrapper->BindThrottleAction(PlayerInputComponent, this, &ASomePlayerPawn::UpdateThrottle);
}
I’m sure there’s a bunch wrong here, and I can’t seem to get the UpdateThrottleSignatureAddr
parameter correctly defined so that I can pass it to EnhancedInputComponent->BindAction()
The only other ways I know how to do this are:
- Use the
EnhancedInputComponent
method that takes a function nameFName FunctionName
, and have PlayerPawn pass an FName. But my goal is to make this strongly typed, and I generally want to avoid passing function names as strings. - Create a
UInterface
that theASomePlayerPawn
conforms to, and haveInputWrapper::BindThrottleAction
accept the interface. However my goal is a complete separation of concerns, so I’d prefer not to have the Interface a requirement.
Before I move onto option 2, I wanted to see if there was a more streamlined way, so that PlayerPawn doesn’t have to declare that it conforms to an interface, basically like how EnhancedInputComponent->BindAction works.
For reference here’s the generic typed EnhancedInputComponent method I’m trying to pass the signature to:
template<class UserClass>
FInputActionBinding & BindAction
(
const FName ActionName,
const EInputEvent KeyEvent,
UserClass * Object,
typename FInputActionHandlerWithKeySignature::TUObjectMethodDelegate< UserClass >::FMethodPtr Func
)
Thanks!