Enhanced Input System

Hi, i have trouble with Enhanced Input System
In BeginPlay i use:

APlayerController* PlayerController = Cast<APlayerController>(GetController());
    if (PlayerController)
    {
        UEnhancedInputLocalPlayerSubsystem *Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer());
        if (Subsystem)
        {
            Subsystem->ClearAllMappings();
            Subsystem->AddMappingContext(InputContext, 0);
        }
    }

then i override SetupPlayerInputComponent Binding the action

void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {
    Super::SetupPlayerInputComponent(PlayerInputComponent);

    FString Name = GetName();
    UE_LOG(LogTemp, Warning, TEXT("Setup %s"), *Name);

    UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent);
    EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ATank::Move);
}

the Move function is:

void ATank::Move(const FInputActionValue& value) {
    UE_LOG(LogTemp, Warning, TEXT("Move: %f"), value.Get<float>());
}

MoveAction and InputContext are setted in BluePrint editor to correct InputAction and InputMappingContext objects if i use the command showdebug enhancedinput i see that it detects the key pressed, i check in the logs and the BindAction is successful, but seems that the Move function never get called…

Thanks.

You don’t create an EnhancedInputComponent, you cast the InputComponent you get to an EnhancedInputComponent.

Like this:

void AMyCharacter::SetupPlayerInputComponent(UInputComponent* pPlayerInputComponent)
{
  Super::SetupPlayerInputComponent(pPlayerInputComponent);

  if (UEnhancedInputComponent* pEnhancedInputComponent = Cast<UEnhancedInputComponent>(pPlayerInputComponent))
  {
    pEnhancedInputComponent->BindAction(m_pJumpAction, ETriggerEvent::Started, this, &ACharacter::Jump);

At least, this is how I learned it.
Perhaps I am wrong. :slight_smile:

1 Like