Player Click Fire for Unreal 5.3

Hey all, Just wanted to share an update for Unreal 5.3 and the new Input mapping and everything. Following in Hwennlof’s footsteps from the Handling Input lecture, I just wanted to add a clarification for the Fire action. In Tank.cpp, I initially had in the SetupPlayerInputComponent the following:

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

    auto PlayerController = Cast<APlayerController>(GetController());

    auto EISubsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer());
    EISubsystem->AddMappingContext(InputMapping, 0);

    auto PlayerEIComponent = Cast<UEnhancedInputComponent>(PlayerInputComponent);

    PlayerEIComponent->BindAction(InputMoveForward, ETriggerEvent::Triggered, this, &ATank::Move);
    PlayerEIComponent->BindAction(InputTurn,ETriggerEvent::Triggered, this, &ATank::Turn);
    PlayerEIComponent->BindAction(InputFire,ETriggerEvent::Triggered, this, &ATank::Fire);
}

while doing this, holding down the mouse button would trigger the DebugSphere many times, instead of the one time we wanted.


After looking at the ETriggerEvent documentation, I realized what we want is to use the following for our InputFire BindAction:

    PlayerEIComponent->BindAction(InputFire,ETriggerEvent::Started, this, &ATank::Fire);

Which now gives us the desired result of looking like the video!

Hope you find this helpful!

1 Like

Privacy & Terms