fc2ブログ

凛(kagring)のUE5/UE4とゲーム制作と雑記ブログ

2016 年から UE4 / 2021年から UE5 を触り始めました。勉強したもののメモ用ブログです。ゲーム制作に関するメモや雑記とか色々あります。C++ での Qt、Unity もほんの少しあります。

PREV | PAGE-SELECT | NEXT

≫ EDIT

UE5/UE4 C++でアニメーション通知(Animation Notifications)の「AnimNotifyState」を作成する(UAnimNotifyState)

C++でアニメーション通知(Animation Notifications)の「AnimNotifyState」を作成する方法です。

こちらを参考にさせていただきました。

・UE4 AnimNotifyをC++で書く場合のメモ
https://qiita.com/unknown_ds/items/ecadbe7b76cb3b1835d9

公式ドキュメントはこちら。

・UAnimNotifyState
https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/Animation/AnimNotifies/UAnimNotifyState/

アニメーション通知(Animation Notifications)の「AnimNotifyState」を作るには
「UAnimNotifyState」を継承したクラス
を作成します。

まずはヘッダの定義になります。

#include "Animation/AnimNotifies/AnimNotifyState.h"

// AnimNotifyStateクラス
class UAnimNotifyState_New : public UAnimNotifyState
{

GENERATED_BODY()
public:
// コンストラクタ
UAnimNotifyState_New ();
public:
// Notify 設定
virtual FString GetNotifyName_Implementation() const override;
virtual void NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase * Animation, float TotalDuration, const FAnimNotifyEventReference& EventReference);
virtual void NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase * Animation, const FAnimNotifyEventReference& EventReference);
virtual void NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase * Animation, float FrameDeltaTime, const FAnimNotifyEventReference& EventReference);
public:
// 公開変数
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 Value;
};

上記で「UAnimNotifyState」を継承したクラスを作成しました。

「GetNotifyName_Implementation」関数は「Notify」を配置した場合に表示される文字列を記述します。
・「NotifyBegin」関数は「Notify」が開始した時の処理を記述します。
・「NotifyEnd」関数は「Notify」が終了した時の処理を記述します。
・「NotifyTick」関数は「Notify」が実行中の処理を記述します。
・変数を定義することで「Notify」のパラメータとして受け取ることができます。

次に実際の処理を記述します。

・通知が開始された時の処理(NotifyBegin)

// 通知が開始された時の処理
void UAnimNotifyState_New ::NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float TotalDuration, const FAnimNotifyEventReference& EventReference)
{

// 取得
TObjectPtr< AActor> aActor = Cast< AActor>(MeshComp->GetOwner());

// 何か処理色々
}


・通知が終了した時の処理(NotifyEnd)

// 通知が終了した時の処理
void UAnimNotifyState_New ::NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference)
{

// 取得
TObjectPtr< AActor> aActor = Cast< AActor>(MeshComp->GetOwner());

// 何か処理色々
}


・通知が実行中の処理(NotifyTick)

// 通知が実行中の処理
void UAnimNotifyState_New ::NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float FrameDeltaTime, const FAnimNotifyEventReference& EventReference)
{

// 取得
TObjectPtr< AActor> aActor = Cast< AActor>(MeshComp->GetOwner());

// 何か処理色々
}


こんな感じで通知がきたときの処理を書くことができます。

簡単な通知はBPで作ってしまったほうが良い場合もありますが、
ある程度複雑な処理の場合はC++で書いた方が楽なのかなと思いました。

| UE5 | 10:00 | comments:0 | trackbacks:0 | TOP↑

COMMENT















非公開コメント

TRACKBACK URL

http://kagring.blog.fc2.com/tb.php/782-d280e1f5

TRACKBACK

PREV | PAGE-SELECT | NEXT