UE5.0.2 Access from a UAnimInstance class to a Variable in the ACCharacter class C++

UNREAL 5

When I try to access a variable that is in ACCharacter::MyACharacterClass from UAnimInstance::MyAnimationClass; when I put the code in NativeBeginPlay(); does not generate conflicts, but when I put the code in NativeUpdateAnimation(); Unreal Engine crashes.

The distribution of my code is: I create a global variable in the .cpp of the MyAnimationClass class;

AMyACharacterClass* variableCharacter

Inside the NativeBeginPlay();

variableCharacter= Cast(GetOwningActor());

Inside the NativeUpdateAnimation();

bool VariableAccess= CharacterVariable->DesiredVariable

In this way Unreal Crash, to place the last line in the NativeBeginPlay(); I access the variable without problem.

My need for it to be in NativeUpdateAnimation(), is to be able to update the animation that depends on that variable

I think you should put AMyACharacterClass* variableCharacter inside your .h file class.
If you don’t want then to be accessed by other class, set it to private.

private:
   AMyACharacterClass* variableCharacter
1 Like

No, remember something, the access to the variables and functions I already have, but only when I try to do it in NativeBeginPlay(). But since I constantly need to check a specific variable, when I try to do it in NativeUpdateAnimation()… Crash.

Thanks for the interest…