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?

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

Many thanks,
Matt.

Hey @fallingbrickwork , I posted an answer on your forum post, but I would like to post it here as well so others can find it.

I believe you are getting the action bound twice because AMM2PlayerControllerTapeRecorder::SetupInputComponent() is being called twice: once in your BeginPlay() function, and once in the engine code.

To fix this, simply remove SetupInputComponent() from your BeginPlay() function.

1 Like

Yes you are correct, how did i not think of this, I didn’t think that the SetupInputComponent() would be automatically called, and even if it was it wouldn’t allow for duplicate Bindings. I’ve learned something new today!