UE4-動畫/蒙太奇/融合(Animation/montage/blend)相關筆記


Q.定義狀態機動畫藍圖事件:

 

 

 

Q.Animation/Montage指定幀觸發事件(Event):

(注意:單幀動畫需要取消勾選Teleport to Explicit Time,否則無法觸發幀事件)

 

Q.C++自定義 Animation Blueprint(動畫藍圖)

 

自己很少用C++寫Skeleton動畫相關的邏輯,通常Anim的BP滿足大部分需求,最多繼承一個UAnimInstance封裝一個通用基類,很少去自定義anim節點

 

故留個C++實現備查.

 

Note:AnimGraph屬於Edtior模塊,如果需要打包,需要注意下build.cs:

 

https://github.com/Hethger/UE4_AnimGraphNode_Project_Template 

 

build.cs主要片段:

        if (Target.Type == TargetType.Editor)
        {
            PublicDependencyModuleNames.AddRange(
                new string[] 
                {
                    "UnrealED",
                    "BlueprintGraph",
                    "AnimGraph"
                });
        }

 

AnimInstance 栗子:

.h

UCLASS(transient, Blueprintable , hideCategories = AnimInstance, BlueprintType )
class BJ_3DDESIGNAPP_API UCppAnimation_Demonstrate : public UAnimInstance
{
    GENERATED_BODY()
public:
    //初始化虛函數
    virtual void NativeInitializeAnimation() override;
    //tick event 
    virtual void NativeUpdateAnimation(float DeltaTimeX) override;
protected:
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CppVariant")
        float Speed = 0.0f;
};

 .cpp

void UCppAnimation_Demonstrate::NativeInitializeAnimation()
{ Super::NativeInitializeAnimation(); }
void UCppAnimation_Demonstrate::NativeUpdateAnimation(float DeltaTimeX) { Super::NativeUpdateAnimation(DeltaTimeX);
  //你的邏輯
}

 

Q.C++自定義 Animation Graph Node (動畫節點)

  需要C++自定義動畫節點的話,需要分別實現UAnimGraphNode_Base,和FAnimNode_Base的子類;

  UAnimGraphNode_Base用於在Editor里的定義一些節點的屬性(如顏色/Category 名稱/節點名等)

  FAnimNode_Base 里實現我們自己的動畫邏輯

 栗子(PS:例子是沒有實現任何功能的):

 

AnimNode:

 

.h

 

 

 
         

#pragma once

 
         

#include "CoreMinimal.h"
#include "Animation/AnimNodeBase.h"
#include "CppAnimNode_Demonstrate.generated.h"


USTRUCT(BlueprintType)
struct BJ_3DDESIGNAPP_API FCppAnimNode_Demonstrate : public FAnimNode_Base { GENERATED_USTRUCT_BODY() public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Links) FPoseLink BasePose; public: virtual void Initialize_AnyThread(const FAnimationInitializeContext& Context) override; virtual void CacheBones_AnyThread(const FAnimationCacheBonesContext& Context) override; virtual void Update_AnyThread(const FAnimationUpdateContext& Context) override; virtual void Evaluate_AnyThread(FPoseContext& Output) override; virtual void GatherDebugData(FNodeDebugData& DebugData) override; // Constructor public: FCppAnimNode_Demonstrate(); };

 

.cpp

#include "CppAnimNode_Demonstrate.h"

FCppAnimNode_Demonstrate::FCppAnimNode_Demonstrate() { }
void FCppAnimNode_Demonstrate::Initialize_AnyThread(const FAnimationInitializeContext & Context) { BasePose.Initialize(Context); } void FCppAnimNode_Demonstrate::CacheBones_AnyThread(const FAnimationCacheBonesContext & Context) { BasePose.CacheBones(Context); } void FCppAnimNode_Demonstrate::Update_AnyThread(const FAnimationUpdateContext & Context) { EvaluateGraphExposedInputs.Execute(Context); BasePose.Update(Context); } void FCppAnimNode_Demonstrate::Evaluate_AnyThread(FPoseContext & Output) { BasePose.Evaluate(Output); } void FCppAnimNode_Demonstrate::GatherDebugData(FNodeDebugData & DebugData) { FString DebugLine = DebugData.GetNodeName(this); DebugData.AddDebugItem(DebugLine); BasePose.GatherDebugData(DebugData); }

 

AnimGraphNode:

.h

#pragma once

#include "CoreMinimal.h"
#include "AnimGraphNode_Base.h"
#include "CppAnimNode_Demonstrate.h"
#include "CppAnimGraphNode_Demonstrate.generated.h"


UCLASS() class BJ_3DDESIGNAPP_API UCppAnimGraphNode_Demonstrate : public UAnimGraphNode_Base { GENERATED_UCLASS_BODY() private: //注意,自定義的Anim Node類,邏輯都在里面 UPROPERTY(EditAnywhere, Category = "Settings") FCppAnimNode_Demonstrate Node; public: //節點顏色 virtual FLinearColor GetNodeTitleColor() const override; //提示內容 virtual FText GetTooltipText() const override; //節點名稱 virtual FText GetNodeTitle(ENodeTitleType::Type TitleType) const override; //Category 分類名稱 virtual FString GetNodeCategory() const override; };

.cpp

#include "CppAnimGraphNode_Demonstrate.h"

#define LOCTEXT_NAMESPACE "LQ" UCppAnimGraphNode_Demonstrate::UCppAnimGraphNode_Demonstrate(const FObjectInitializer& ObjectInitializer) :Super(ObjectInitializer) { } FLinearColor UCppAnimGraphNode_Demonstrate::GetNodeTitleColor() const { return FLinearColor::Green; } FText UCppAnimGraphNode_Demonstrate::GetTooltipText() const { return LOCTEXT("hello_ue4_animation ", "hello_ue4_animation "); } FText UCppAnimGraphNode_Demonstrate::GetNodeTitle(ENodeTitleType::Type TitleType) const { return LOCTEXT("HandleCharacterHeight", "HandleCharacterHeight"); } FString UCppAnimGraphNode_Demonstrate::GetNodeCategory() const { return TEXT("CppCustomNode"); } #undef LOCTEXT_NAMESPACE

 

 

Q.C++ 自定義State machine狀態機

  wait


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM