Download

GetAnimInstance on begin play?

Should be pretty simple right? wrong.
It’s not returning the actual value.

Got this in .h

	UPROPERTY(BlueprintReadWrite, VisibleAnywhere);
	USkeletalMeshComponent* SkeletalMeshInstance;
	UPROPERTY(BlueprintReadWrite, VisibleAnywhere);
	UAnimInstance*	AnimationInstance;

This on construction

	SkeletalMeshInstance = GetMesh();

this on begin play (because I doubt it would be initialized and set to an actual instance anytime before that).

	if (SkeletalMeshInstance->HasValidAnimationInstance()) {
		AnimationInstance = SkeletalMeshInstance->GetAnimInstance();
	}

Now, if in BP I printstring AnimationInstance
I get NULL on BeginPlay
But I get the right result i’m looking for on EventTick

Suggestions on why this isn’t working @ begin play?
Does BP begin Play trigger prior to C++ begin play?

NOTE:
I’m doing it this way to create a master character class that doesn’t need to cast to specific animation instance to update it’s variables - if anyone has any better C++ alternatives to that please do share :slight_smile:

We have a class that inherits from “USkeletalMeshComponent” that calls GetAnimInstance() immediately on BeginPlay().

One place you could be going wrong … are you calling GetAnimInstance() after calling Super::BeginPlay()? If not that could cause a problem.

void UInteractiveSkeletalMesh::BeginPlay()
{
	Super::BeginPlay();

	// do something with anim instance
	UAnimInstance* animationInstance = GetAnimInstance();
       if (animationInstance != nullptr)
      {
           // ...
      } 
}

Thanks for the response.

It’s really just blueprint that doesn’t like it.

Haven’t tested the stack, but it think beginplay on the blueprint side is happening prior to the c++ one.

I ended up also creating a c++ animation to pass things along directly off c++ which seems to perform faster anyway.