0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【UE5】【修正版】Character Movement Componentを使わずにルートモーションする

Posted at

やりたいこと

  • ルートモーションを使いたい。
  • だが、Character Actorクラス+Character Movement Componentで作るほど大げさにしたくない。
  • 普通のActor (またはPawn)+Skeletal Mesh Componentでサクッとやりたい。
  • Blueprintで使えるノードが欲しい。

以前の記事との違い

この記事は、以前書いた【UE4】Character Movement Componentを使わずにルートモーションする…の修正版となります。

以前の記事では、UAnimInstance::ConsumeExtractedRootMotion()を使ってルートモーションを抽出する方法を紹介しましたが、この方法では Animation Blueprint Linkingや Post Process Anim Blueprintを使っている場面に対応できません。USkeletalMeshComponent::ConsumeRootMotion()の内部でこれらに対応するコードが書かれているので、この関数を使うことで、この問題を回避できます。

C++ソース例

以前の記事の場合と違い、UAnimInstanceを直接使う必要はないので、Blueprint Function Libraryに関数を記述することにします。

MyBlueprintFunctionLibrary.h
UCLASS()
class UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
	
public:

	// このフレームのルートモーションによるDelta Transformを取得する
	UFUNCTION(BlueprintCallable, Category = "My Blueprint Function Library|Animation")
	static UPARAM(DisplayName = "DeltaTransform") FTransform ConsumeRootMotion(USkeletalMeshComponent * InMeshComp);
};
MyBlueprintFunctionLibrary.cpp
FTransform UMyBlueprintFunctionLibrary::ConsumeRootMotion(USkeletalMeshComponent* InMeshComp)
{
	if (IsValid(InMeshComp))
	{
		// Skeletal Mesh Componentにルートモーションを計算(消費=consume)させる
		FRootMotionMovementParams Params = InMeshComp->ConsumeRootMotion();
		if (Params.bHasRootMotion)
		{
			// ワールド座標系に変換してreturnする
			return InMeshComp->ConvertLocalRootMotionToWorld(Params.GetRootMotionTransform());
		}
	}

	return FTransform::Identity;
}

Blueprintでの使用例

C++側でWorld座標系のDelta Transformに変換済みなので、シンプルにAddActorWorldTransformに渡すだけです。

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?