Cast variable to Animation BP

Hi,
I have a variable in the character c++ class that I want in the animation blueprint. I managed to get it there by casting in the character blueprints, however I want to do this with c++.

Basically I need to convert this to c++, or another method.

I have tried this but got an error stating: " 'MovementDirection ': is not a member of ‘UAnimInstance’ ".

cpp

 Mesh = FindComponentByClass<USkeletalMeshComponent>();
	AnimInstance = Mesh -> GetAnimInstance();

	AnimationBP = Cast<UAnimInstance>(AnimInstance);

	if(AnimationBP)
	{
		 AnimationBP->MovementDirection = Axis;
		
	}

h

USkeletalMeshComponent* Mesh;
UAnimInstance * AnimInstance;
UAnimInstance * AnimationBP;

AnimationBP->MovementDirection seems to be a bp variable which is very hard to set in C++

would recommend creating your own AnimationInstance in C++ with the MovementDirection variable, then casting to it is not a problem

UCLASS()
class UMyAnimInstance : public UAnimInstance
{
  GENERATED_BODY()

public:
  UPROPERTY(EditAnywhere, BlueprintReadWrite)
  FVector MovementDirection;

};

MyAnimation = Cast<UMyAnimInstance>(AnimInstance);
 
     if(MyAnimation )
     {
          MyAnimation->MovementDirection = Axis;
         
     }

I see. I created an Anim Instance c++ class and made it the parent class of my animation blueprint. What would the AnimInstance have to be now? I am getting an error for casting.

h

UMyAnimInstance * AnimationBP;

cpp

AnimationBP = Cast<UMyAnimInstance>(AnimInstance);

what’s the error?

There is a very large log:

Think you are missing the include for UMyAniminstance in Default_Player.cpp

Yesss, it works now. I realized I had the wrong include.
Thank you very much for the assistance.