How to properly enable/disable input bindings on the fly.

I have a few Axis input bindings that I want to enable/disable on the fly easily.

BindAxis returns an FInputBinding reference. I tried storing a pointer to the input binding. I noticed it says in the docs: “Returned reference is only guaranteed to be valid until another axis is bound.” so I guess the InputBinding object is later copied or something?

FInputBinding has a bConsumeInput field but changing it has no results.

I also tried using the index instead like this, which also didn’t work:

Debug3PMoveForwardBinding = InputComponent->AxisBindings.Num();
InputComponent->BindAxis(FSFMovementAxisInputConstants::Instance.MoveForward, this, &ASFPlayerController::Debug3PMoveForward);

InputComponent->AxisBindings[Debug3PMoveForwardBinding].bConsumeInput = false;

Maybe you just add a boolean inside your input method, something like this.



void MyProject::MoveForward(float value)
{
    if(bCanMoveForward)
    {
        // code to move
    }
}


That is one option.

I have it set up so my character binds the movement controls. That way you can build any kind of character or vehicle or whatever, and its upto the possessed pawn to define what “MoveForward” means. Like a ground character binds MoveForward to walking forward. A vehicle binds MoveForward to drive forward. A menu can bind MoveForward to scroll up.

From here, the input stack determines which move forward input takes effect. A character can get in a vehicle and now the vehicle’s MoveForward binding is consumed instead of the character’s MoveForward binding.

In this case I have a random debug feature in my player controller that binds MoveForward to moving a debug camera forward. I want to disable or enable the input binding. I’d think that the property bConsumeInput should work but it doesn’t.

This wont actually work. If you remove it the current Input indexes shift, so the index of any other bind is no longer true. Looking how to solve this problem. For ActionBinds its pretty straighforward but for some reason there is no function to remove binds on axis

Yeah I noticed that too. I ended up just adding booleans to filter out the input. I was trying to avoid this since it was specifically for debugging so I only bind the inputs when I enable the debugging mode and they stay bound for ever.