🎬

[Unreal Engine 5] アニメーションの合成と切り替え

2025/02/22に公開

やりたいこと

  1. 移動中、上半身では攻撃アニメーション、下半身では歩行アニメーションを再生する
  2. 歩いていないときは全身で攻撃アニメーションを再生する
  3. 必殺技みたいなものを出すときは Root Motion を使用して全身でアニメーションを再生する

1 と 2 に関しては 参考にしたページ の解説が詳しい。

アニメーションの準備

アニメーションの準備やコントローラーの設定は 殴って吹き飛ばす を参照。

今回は「移動しながら発動できる通常攻撃」として Punching、「専用の全身アニメーションがある必殺技」として Flying Knee Punch ComboMixamo からインポートした。
PunchingRoot Motion = FalseFlying Knee Punch ComboRoot Motion = True とする。

Root Motion を使用しているかどうかの判定

  • ABP_Manny または Retarget して作成した ABP を開く
  • 「+」ボタンを押して Boolean の変数を追加する。今回は IsPlayRootMotion とした。
  • EventGraph を開き、Is Playing Anim Root Motion の戻り値を変数にセットする。

AnimGraph の中で Get CharacterIs Playing Anim Root Motion と接続して値を取得することも可能だが、スレッドセーフではないと警告が出る。
EventGraph で取得した方が無難。

Node Blend Poses by bool uses potentially thread-unsafe call Get Character . Disable threaded update or use a thread-safe call. Function may need BlueprintThreadSafe metadata adding.

Animation の合成

  • Main States を複数ノードの入力で使用するため New Save cached poseUse cached pose を使う。今回は basic motion という名前でキャッシュした。
  • Layered blend per bone でアニメーションを合成する
    • Base Posebasic motion を入力する
    • Blend PoseDefault Slot を入力する
      • Default Slotbasic motion を入力する
    • Layered blend per bone を選択する
      • Layer SetupBranch Filters の 「+」ボタンを押す
      • Bone Name に上半身の付け根に当たるボーンを指定する。今回は J_Bip_C_Sine を指定
      • (合成するアニメーションによる) Blend Depth を 3 に設定する
      • (合成するアニメーションによる) Mesh Spece Rotation BlendTrue に設定する

ここまでで「やりたいこと」の 1 は完了。

  • Blend Poses by bool でアニメーションを合成する
    • True PoseLayered blend per bone を入力する
    • False PoseDefault Slot を入力する
      • Default Slotbasic motion を入力する
    • Active Value に条件を入力する
      • 以下の AND 条件
        • Velocity > 0.0 (= Character が移動している)
        • Is Playing Root Motion = False (Root Motion の再生中ではない)

これで「やりたいこと」の 2 と 3 が完了。

参考にしたページ

https://qiita.com/4_mio_11/items/c909d1a7d82ef054316b
https://www.youtube.com/watch?v=wJRAcnuSn40

Discussion