Loading...
Loading...
Set up player input in Unreal Engine 5 with Enhanced Input: Input Actions, Input Mapping Contexts, modifiers and triggers, adding the mapping context, and binding actions by ETriggerEvent. Use when wiring movement/look/jump input, creating IA_/IMC_ assets, binding in C++ or Blueprints, or when the user mentions Enhanced Input, Input Mapping Context, Input Action, IA_/IMC_, or ETriggerEvent.
npx skill4agent add gamedev-skills/awesome-gamedev-agent-skills unreal-enhanced-inputIA_IMC_IA_*IMC_*EnhancedInputinput-systemsunreal-cpp-gameplay"EnhancedInput"PublicDependencyModuleNames*.Build.csIA_Digital (bool)Axis1D (float)Axis2D (Vector2D)IMC_EnhancedInputLocalPlayerSubsystemAddMappingContext(IMC, Priority)BeginPlayETriggerEventTriggeredStartedCompletedEnhancedInputComponentFInputActionValueshowdebug enhancedinputvoid AMyCharacter::BeginPlay()
{
Super::BeginPlay();
if (APlayerController* PC = Cast<APlayerController>(GetController()))
if (ULocalPlayer* LP = PC->GetLocalPlayer())
if (auto* Subsystem = LP->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>())
Subsystem->AddMappingContext(DefaultMappingContext, /*Priority*/ 0);
}
// DefaultMappingContext is a UPROPERTY(EditAnywhere) TObjectPtr<UInputMappingContext>.void AMyCharacter::SetupPlayerInputComponent(UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
// The component is an Enhanced Input component when the plugin is active.
if (UEnhancedInputComponent* EIC = Cast<UEnhancedInputComponent>(InputComponent))
{
EIC->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AMyCharacter::Move);
EIC->BindAction(LookAction, ETriggerEvent::Triggered, this, &AMyCharacter::Look);
EIC->BindAction(JumpAction, ETriggerEvent::Started, this, &ACharacter::Jump);
EIC->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
}
}
void AMyCharacter::Move(const FInputActionValue& Value)
{
const FVector2D Axis = Value.Get<FVector2D>(); // Axis2D action
AddMovementInput(GetActorForwardVector(), Axis.Y);
AddMovementInput(GetActorRightVector(), Axis.X);
}Event BeginPlay
-> Get Controller -> Cast To PlayerController -> Get Local Player
-> Get EnhancedInputLocalPlayerSubsystem -> Add Mapping Context (IMC_Default, Priority 0)
// IA_Move is exposed as its own event node in the Character's Event Graph:
EnhancedInputAction IA_Move (Triggered)
-> Action Value (Vector2D) -> Add Movement Input (Forward * Y, Right * X)AddMappingContextBeginPlay"EnhancedInput"Build.csPublicDependencyModuleNamesGet<FVector2D>()Get<T>()TriggeredStartedCompletedRemoveMappingContextreferences/cpp-setup.mdhttps://dev.epicgames.com/documentation/en-us/unreal-engine/enhanced-input-in-unreal-engineinput-systemsunreal-cpp-gameplayfps-shooter