I try to make a Animation blueprint. I kinda copy/followed this article
But I can’t get the AnimInstance. I keep getting the error 'AnimInstance': is not a member of 'FAnimationInitializeContext'
In the header file of FAnimationInitializeContext is indeed no AnimInstance member. But how can I get the SkelmeshComponent? and The Actor? All examples I found online are also doing it this way. When I remove ‘Context.AnimInstance’ everything is working.
Is there more recent documentation? Or does anyone know the answer? Or a example code?
PA_AnimNode_WhipTarget.h
#pragma once
#include “AnimGraphNode_Base.h”
#include “AnimGraphNode_SkeletalControlBase.h”
#include “PA_AnimNode_WhipTarget.generated.h”
USTRUCT()
struct FPA_AnimNode_WhipTarget : public FAnimNode_Base
{
GENERATED_USTRUCT_BODY()
//FPoseLink - this can be any combination
//of other nodes, not just animation sequences
// so you could have an blend space leading into
//a layer blend per bone to just use the arm
// and then pass that into the PoseLink
/** Base Pose - This Can Be Entire Anim Graph Up To This Point, or Any Combination of Other Nodes*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Links)
FPoseLink BasePose;
/** Other Pose! - This Can Be Entire Anim Graph Up To This Point, or Any Combination of Other Nodes */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Links)
FPoseLink OtherPose;
/** Sample Property That Will Show Up as a Pin */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Links, meta = (PinShownByDefault))
float SampleFloat;
// FAnimNode_Base interface
public:
// FAnimNode_Base interface
virtual void Initialize(const FAnimationInitializeContext& Context) override;
virtual void CacheBones(const FAnimationCacheBonesContext & Context) override;
virtual void Update(const FAnimationUpdateContext & Context) override;
virtual void Evaluate(FPoseContext& Output) override;
// End of FAnimNode_Base interface
// Constructor
public:
FPA_AnimNode_WhipTarget();
protected:
bool WorldIsGame;
AActor* OwningActor;
};
PA_AnimNode_WhipTarget.cpp
#include "Marigold.h"
#include "PA_AnimNode_WhipTarget.h"
FPA_AnimNode_WhipTarget::FPA_AnimNode_WhipTarget()
: FAnimNode_Base()
, SampleFloat(128.333)
{
WorldIsGame = false;
}
void FPA_AnimNode_WhipTarget::Initialize(const FAnimationInitializeContext & Context)
{
//Init the Inputs
BasePose.Initialize(Context);
OtherPose.Initialize(Context);
//Get the Actor Owner
//Error: 'AnimInstance': is not a member of 'FAnimationInitializeContext'
OwningActor = Context.AnimInstance->GetSkelMeshComponent()->GetOwner();
//Editor or Game?
//Error: 'AnimInstance': is not a member of 'FAnimationInitializeContext'
UWorld * TheWorld = Context.AnimInstance->GetWorld();
if (!TheWorld) return;
//~
WorldIsGame = (TheWorld->WorldType == EWorldType::Game);
}
void FPA_AnimNode_WhipTarget::CacheBones(const FAnimationCacheBonesContext & Context)
{
BasePose.CacheBones(Context);
OtherPose.CacheBones(Context);
}
void FPA_AnimNode_WhipTarget::Update(const FAnimationUpdateContext & Context)
{
//***************************************
// Evaluate Graph, see AnimNode_Base, AnimNodeBase.h
EvaluateGraphExposedInputs.Execute(Context);
//***************************************
//EDITOR
//Editor mode? just use the base pose
if (!WorldIsGame)
{
//if your node depends on
//actual actor instance, can't do anything in editor
}
//GAME
//Actually in Game so the Owner Instance Should Exist
else
{
//Try Again if not found
//Error: 'AnimInstance': is not a member of 'FAnimationInitializeContext'
if (!OwningActor) OwningActor =
Context.AnimInstance->GetSkelMeshComponent()->GetOwner();
//Not found
if (!OwningActor)
{
UE_LOG(LogAnimation, Warning,
TEXT("FAnimNode_NameOfYourNode::Update() Owning Actor was not found"));
return;
//~
}
}
BasePose.Update(Context);
}
void FPA_AnimNode_WhipTarget::Evaluate(FPoseContext & Output)
{
// Return Base Pose, Un Modified
BasePose.Evaluate(Output);
}
Thanks!