Can I Bind an Input to an Action and an Axis?

Is it possible to Bind an input to an axis and trigger separate functions when the key is pressed and released?

	void AMech::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
    {
        PlayerInputComponent->BindAxis("AltMove", this, &AMech::AltMove);
	    PlayerInputComponent->BindAction("AltMove", IE_Pressed, this, &AMech::AltMoveStart);
	    PlayerInputComponent->BindAction("AltMove", IE_Released, this, &AMech::AltMoveEnd);
    }

If not, I guess I can track the action by setting a bool in my movement component and flipping it false if my axis input is 0.

Thanks in advance!

The Action and Axis mappings are different things. When you call BindAxis or BindAction, you’re not binding a key directly, you’re binding a mapping with the given label to a method that will respond to it. Action Mappings and Axis Mappings create different events with different arguments passed in. You won’t get an IE_Pressed from an axis, you just get the float value; likewise, an Action Mapping doesn’t give you a float input value.

What you can do is create an Action Mapping and an Axis Mapping for the same key, and then tie your BindAxis and BindActions to those mappings. You can call them “AltMove” and “AltMoveClick”, create “AltMove” as an Axis Mapping and create “AltMoveClick” as an Action Mapping, then you just need to change the name of the mapping in the BindAction calls in your code above.

In fact; the engine might even let you name an ActionMapping and an AxisMapping with the same label; but unless you create them both either your BindAction or BindAxis won’t do anything, because they only search for Action Mappings and Axis Mappings respectively. And in that case, you’re not binding the same mappings to your events, you’re binding the “AltMove” Axis Mapping with BindAxis, and you’re binding the “AltMove” Action Mapping with BindAction.

Awesome, thanks! The BindAction and BindAxis can have the same name as long as they each have a mapping under “Edit → Project Settings → Engine/Input”.

Way more convenient than polling the axis float value. Thanks again.

No problem. Glad to help!

Please mark as resolved so others searching for the same question can find the answer.