Error when BindAction on UEnhancedInputComponent

I followed the docs trying to migrate to Enhanced Input. I ran into an error when BindAction.

This is how I call BindAction.

PlayerEnhancedInputComponent->BindAction(MoveForwardAction, ETriggerEvent::Triggered, this, &APlayerCharacter::MoveForward);

MoveForward is declared like this:

void AKusoGameCharacter::MoveForward(const FInputActionValue& Value)

When I compiled the code, I was given an error saying:

Error C2664 ‘void TDelegate<void (void),FDefaultDelegateUserPolicy>::BindUObject<UserClass,>(UserClass ,void (__cdecl APlayerCharacter:: )(void))’: cannot convert argument 2 from ‘FuncType’ to ‘void (__cdecl APlayerCharacter::* )(void)’ KusoGame F:\Program Files\Epic Games\UE_5.0\Engine\Plugins\Experimental\EnhancedInput\Source\EnhancedInput\Public\EnhancedInputComponent.h 374

It seems that it calls an overloaded version which takes the delegate without arguments. I tried create a FEnhancedInputActionHandlerValueSignature manually and pass it in. It still gave me same error.

1 Like

Did you mark your void MoveForward(const FInputActionValue& Value) as UFUNCTION() ?
AFAIC, input functions require it.

I marked, same error.

I tried another way to pass the handler function, it worked. But I’m still wondering why it does not compile with the raw function pointer.

Here is what I did:

FEnhancedInputActionHandlerValueSignature::TMethodPtr<ThisClass> MethodPointer = &APlayerCharacter::MoveForward;
PlayerEnhancedInputComponent->BindAction(MoveForwardAction, ETriggerEvent::Triggered, this, MethodPointer);

I checked the source, found that three of the BindActions are defined by a macro DEFINE_BIND_ACTION(HANDLER_SIG), where HANDLER_SIG is one of the three kinds of delegate: FEnhancedInputActionHandlerSignature, FEnhancedInputActionHandlerValueSignature, FEnhancedInputActionHandlerInstanceSignature.

The generated BindAction will take typename HANDLER_SIG::TMethodPtr< UserClass > Func as the action handler.

But somehow when I pass a raw function pointer like the docs does, it calls

template< class FuncType, class UserClass, typename... VarTypes >
FEnhancedInputActionEventBinding& BindAction(const UInputAction* Action, ETriggerEvent TriggerEvent, UserClass* Object, FuncType Func, VarTypes... Vars)

defined on line 371 in EnhancedInputComponent.h

Confusing, hope someone can tell me why.

And…it seems not necessary to mark the handler function UFUNCTION().

3 Likes