unreal-enhanced-input について
unreal-enhanced-input は、Unreal Engine 5.8 の Enhanced Input を使うためのスキルです。データ駆動のアクションとマッピングコンテキストを扱い、C++ と Blueprint の設定・バインド方法を説明します。
主な機能
- 01Input Action と Mapping Context の作成
- 02モディファイアとトリガーの設定
- 03プレイヤーへのマッピングコンテキスト追加
- 04C++ と Blueprint でのアクションバインド
- 05入力マッピングの問題調査
活用シーン
- 01移動、視点、ジャンプ、射撃入力の実装
- 02キーを Axis2D アクションに割り当て
- 03長押し、タップ、押下イベントの処理
- 04未発火や値の誤りがある入力のデバッグ
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ gamedev-skills/ awesome-gamedev-agent-skills --skill unreal-enhanced-inputインストール後、Claude Code で/unreal-enhanced-inputを入力して読み込まれたか確認します。
同梱ファイルreferences/cpp-setup.md
詳細
Unreal Enhanced Input
レガシーな Project Settings の軸/アクションマッピングの代わりに、データ駆動型の Input Actions と Mapping Contexts を使う Enhanced Input システムで、現代的な UE5 の方法でプレイヤー入力を接続します。 UE 5.8 を対象としています(Enhanced Input がデフォルトで、レガシー入力は非推奨です)。
使用する場面
- 移動/視点操作/ジャンプ/射撃の入力を追加するとき、Input Action(
IA_)と Input Mapping Context(IMC_)のアセットを作成するとき、モディファイアー/トリガーを適用するとき、マッピングコンテキストをプレイヤーに追加するとき、または C++ や Blueprint でアクションをバインドするときに使用します。 - プロジェクトに
IA_*/IMC_*アセットがある場合や、EnhancedInputを参照している場合に使用します。
使用しない場面: エンジンに依存しない入力 アーキテクチャ(再バインド戦略、バッファリング、マルチデバイス設計)には input-systems を使用します。これらのバインドを配置する Pawn/Character の C++ には unreal-cpp-gameplay を使用します。
基本的なワークフロー
- モジュール/プラグインを有効にします。 Enhanced Input は UE5 でデフォルトで有効です。C++ でバインドするには、
*.Build.csのPublicDependencyModuleNamesに"EnhancedInput"を追加します。 - Input Actions(
IA_)を作成します。 それぞれに Value Type があります。ボタンにはDigital (bool)、トリガーにはAxis1D (float)、移動/視点操作にはAxis2D (Vector2D)を使用します。 - Input Mapping Context(
IMC_)を作成し、 キー/ボタンをそれらのアクションにマッピングします。 生の入力を調整するには Modifiers(Negate、Swizzle Input Axis Values、Dead Zone)を使用します。たとえば、WASD を 1 つの Axis2D にまとめるには、A/S に Negate、W/S に Swizzle が必要です。アクションが いつ 発生するかは Triggers(Pressed、Hold、Tap)で指定します。 - プレイヤーにマッピングコンテキストを追加します。
EnhancedInputLocalPlayerSubsystemのAddMappingContext(IMC, Priority)を介して追加します。通常はBeginPlay/ポゼッション時に行います。 - アクションをハンドラーにバインドします。
EnhancedInputComponent上でETriggerEvent(Triggered、Started、Completedなど)を指定してバインドし、ハンドラー内でFInputActionValueを読み取ります。 - PIE で検証します。 Enhanced Input のデバッグ用コンソールコマンド
(
showdebug enhancedinput)を使うと、どのアクションがトリガーされたか、その値を確認できます。
パターン
1. マッピングコンテキストを追加する(C++ Character)
void 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>.
2. アクションをバインドして値を読み取る
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);
}
3. Blueprint での同等の処理(ノードの流れ)
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)
注意点
- 入力がまったくない — マッピングコンテキストが追加されていない(
AddMappingContext)、またはプレイヤーに Local Player がまだありません。ポゼッション後/BeginPlay後に追加してください。 - C++ でのバインド時にリンク/コンパイルエラーが発生する —
Build.csのPublicDependencyModuleNamesに"EnhancedInput"がありません。 - WASD の 2 つのキーでしか移動しない/軸が間違っている — Axis2D には Modifiers が必要です。負のキー(A、S)に Negate を設定し、縦方向(W/S)に Swizzle Input Axis Values を設定して、両方の軸が正しくマッピングされるようにします。モディファイアーなしの生のバインドでは正しく動作しません。
Get<FVector2D>()がゼロを返す — 値の型が一致していません。Input Action が Axis2D ではなく Digital/Axis1D になっています。Get<T>()をアクションの Value Type に合わせてください。- アクションが予期せず毎フレーム発生する — Down トリガーでは、押し続けている間
Triggeredが繰り返されます。1 回だけ発生させる操作(ジャンプの押下/解放)にはStarted/Completed、または Pressed/Tap トリガーを使用してください。 - 2 つのコンテキストが競合する — 複数のマッピングコンテキストは Priority に従って重ねて適用されます。優先度の高いコンテキストがキーを消費することがあります。優先度を管理し、
RemoveMappingContextを使用してください。
参考資料
- Enhanced Input を使った一人称/三人称 C++ Character の完全な例(ヘッダーとソース、視点操作/ジャンプ、および操作の再割り当てに関する注記を含む)については、
references/cpp-setup.mdを参照してください。 - 主要ドキュメント:「Unreal Engine の Enhanced Input」
(
https://dev.epicgames.com/documentation/en-us/unreal-engine/enhanced-input-in-unreal-engine)。
関連スキル
input-systems— エンジンに依存しない入力アーキテクチャと再バインド戦略。unreal-cpp-gameplay— Character/Pawn クラスとモジュールの設定。fps-shooter— 3D コントローラーと射撃に入力を組み合わせます。
コメント
Markdown 対応