Why Isn't "Get Actor Info" Getting My Anim Instance?

While setting up a basic melee system using gameplay abilities in Blueprints, I noticed the PlayMontageAndWait node wasn’t playing anything. Hunting down the error I traced it to its C++ class which told me it was getting a null pointer for the anim instance. Further experimentation showed that while the avatar actor was properly getting my animation blueprint, ActorInfo was not. Since the PlayMontageAndWait node uses ActorInfo, the avatar working properly doesn’t matter and the animation doesn’t play. What’s weird is that the skeletal mesh reference for the ActorInfo is working just fine, but it’s not properly obtaining the anim instance in Unreal’s GameplayAbilityTypes class, even though I can access it directly via Blueprint using the skeletal mesh.

For reference, this is the method for getting the anim instance from the skeletal mesh in the GameplayAbilityTypes class. You might think “oh well it returns null if there’s no skeletal mesh so that must be the problem” but as I’ve hopefully demonstrated you can still get the skeletal mesh just fine and as expected, even using the ActorInfo, so I find that unlikely. And yes, my instance tag is set to “NAME_None” so it should be ignoring that if statement.

UAnimInstance* FGameplayAbilityActorInfo::GetAnimInstance() const
{ 
	const USkeletalMeshComponent* SKMC = SkeletalMeshComponent.Get();

	if (SKMC)
	{
		if (AffectedAnimInstanceTag != NAME_None)
		{
			if(UAnimInstance* Instance = SKMC->GetAnimInstance())
			{
				return Instance->GetLinkedAnimGraphInstanceByTag(AffectedAnimInstanceTag);
			}
		}

		return SKMC->GetAnimInstance();
	}

	return nullptr;
}

So I’m left scratching my head wondering…

  • Why does PlayMontageAndWait use the actor and not the avatar?

  • Why isn’t the anim instance working on the actor but it is on the avatar?

  • What is the actual root cause of this issue in the first place?

The only reason I can see as to why this isn’t working is because I’ve somehow setup my ability system component and the actual character containing it incorrectly (assuming it’s not bugged in some way).

Here’s how the character blueprint is laid out, if it helps:

image_2023-11-28_151046638

I’m currently facing this issue as well. Any chance you got it sorted?

Well I solved it, but not by fixing the problem. I just circumvented it by making a copy of the PlayMontageAndWait class in C++ and directly getting the skeletal mesh from there using avatar actor rather than calling the GetAnimInstance method. Then I just used my version as the Blueprints node replacing the original and it worked. I was hoping this bug would be fixed in 5.4, but if you’re seeing this issue I guess it was not. I still have no idea why it occurs in certain circumstances. I was never able to decipher exactly what action during the abilities or character Blueprint setup causes this to occur.