BindAction firing twice with single button press

Hi all,

I am binding two Actions within my PlayerController like this…



void AMM2PlayerControllerTapeRecorder::BeginPlay()
{
    Super::BeginPlay();

    SetupInputComponent();
}

void AMM2PlayerControllerTapeRecorder::SetupInputComponent()
{
    Super::SetupInputComponent();

    check(InputComponent);

    UE_LOG(LogTemp, Warning, TEXT("Setting up our control bindings"));
    InputComponent->BindAction("TapeRecorderNextTrack", IE_Pressed, this, &AMM2PlayerControllerTapeRecorder::NextTrack);
    InputComponent->BindAction("TapeRecorderPrevTrack", IE_Pressed, this, &AMM2PlayerControllerTapeRecorder::PrevTrack);
}

void AMM2PlayerControllerTapeRecorder::NextTrack()
{
    UE_LOG(LogTemp, Warning, TEXT("Next Track Pressed"));
}

void AMM2PlayerControllerTapeRecorder::PrevTrack()
{
    UE_LOG(LogTemp, Warning, TEXT("Previous Track Pressed"));
}


Everything is working fine, as in it is finding the Device and firing when I click the buttons… problem is, they are firing twice for a single button press!



LogBlueprintUserMessages: [MM2TapeRecorderUI_C_0] Next Track
LogBlueprintUserMessages: [MM2TapeRecorderUI_C_0] Next Track
LogBlueprintUserMessages: [MM2TapeRecorderUI_C_0] Prev Track
LogBlueprintUserMessages: [MM2TapeRecorderUI_C_0] Prev Track


Any ideas what could be causing this?

(edit: btw, i’ve changing the ProjectSettings->Input to different controller buttons and key presses with the same result)

Many thanks,
Matt.

I don’t know what the problem could be. Maybe try debugging some more, make those functions (NextTrack and PrevTrack) UFUNCTION(BlueprintCallable) and in blueprint put an event like “F key” and call those functions and see if it happens twice. Maybe you are doing something somewhere else? Or the device is broken and it registers the button twice :smiley:
An easy fix would be to execute once. You can put an if statement and check if the variable it’s false, when it enters NextTrack() put it true, and OnRelease button put it back to false, I guess that should work.

Is it just the 1 player? No server/client happening?

Thanks for your replies guys… I’ll try and answer your Qs here…

  • yes, it’s just a single player. It’s practically an empty scene, just a couple of static meshes in there. No other functionality apart from this PlayerController.
  • I thought it could be a faulty controller, so mapped Binded those functions to a key press but get the same result.
  • OnRelease() also fires twice.

I moved the Controller functionality to Blueprint and everything is fine, meaning they are firing once only. So as it stands i have it all working, it’s just troubling me why it should be happening. I have my main game Map that is binding controller buttons and that is working just fine. For this scene i created a new GameMode and PlayerController so maybe it is due to that, i really don’t know.

Hey fallingbrickwork, it looks like you’re actually calling SetupInputComponent() twice leading to the action being bound twice.

You don’t need to add SetupInputComponent() in BeginPlay(), since it’ll automatically be called elsewhere.

Hope that helps!

1 Like

Ah many thanks… you are correct! Well i’ve learned something new today, so thanks again!