{ }Blueprint → C++

Unreal Engine 5 · Blueprint → C++

Bind Input Action in Unreal Engine 5 C++UE Docs

Binding an Input Action in C++ uses UEnhancedInputComponent::BindAction inside SetupPlayerInputComponent. You cast the input component to UEnhancedInputComponent and bind a UInputAction to a member function for a given ETriggerEvent.

Blueprint node & C++ equivalent

Header (.h)
UPROPERTY(EditAnywhere, Category="Input")
UInputAction* MoveAction;

void Move(const FInputActionValue& Value);
SetupPlayerInputComponent (.cpp)
#include "EnhancedInputComponent.h"

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

  if (UEnhancedInputComponent* Input = Cast<UEnhancedInputComponent>(PlayerInputComponent))
  {
    Input->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AMyCharacter::Move);
  }
}

What does binding an Input Action do?

Binding connects a UInputAction asset to a function so your code runs when the action fires. In Enhanced Input each binding also specifies a trigger event, such as ETriggerEvent::Triggered, which controls when the callback runs. This replaces the legacy BindAxis and BindAction calls from the old input system.

The C++ equivalent

Override SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) and call Super:: first. Cast the parameter to UEnhancedInputComponent with Cast<UEnhancedInputComponent>(PlayerInputComponent); the cast succeeds only when the project uses Enhanced Input. Then call Input->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AMyCharacter::Move), passing the action, the trigger event, the object, and a member function pointer.

How to declare the action and handler

Expose the action as UPROPERTY(EditAnywhere, Category="Input") UInputAction* MoveAction; so you can assign the asset in a Blueprint subclass. The handler signature is void Move(const FInputActionValue& Value); because Enhanced Input passes the current value of the action. Include EnhancedInputComponent.h for the component type.

Frequently asked questions

Why does the cast to UEnhancedInputComponent fail?+

It returns null when the project's default input component class is not UEnhancedInputComponent. Set the Enhanced Input plugin's component as the default in Project Settings, or the binding code never runs.

What signature should my BindAction handler have?+

Use void FunctionName(const FInputActionValue& Value). Enhanced Input passes the action's value so you can read a float, FVector2D, or bool from it.

Where do I bind input actions in C++?+

Inside the overridden SetupPlayerInputComponent, after calling Super::SetupPlayerInputComponent. That is where the pawn receives its input component.

Related Input (Enhanced Input) nodes

View all Input (Enhanced Input) nodes →