Set animation blueprint through C++?

Hello, I have 2 Skeletal meshes (Mesh and Mesh2), the first has an animation blueprint set on it through the editor.

I’m trying to set the same animation blueprint to Mesh2 through C++ but I can’t get it to work:

//This gives an error, SetAnimInstanceClass expects UClass?

What’s the proper way to use SetAnimInstanceClass? Mesh2 needs to use the same Animation blueprint as Mesh, is there a way to copy the one from Mesh to Mesh2?


Edit: I’m trying to achieve something similar to this, where Mesh2 is/moves identical to Mesh, and has a ‘shield’ material to look like a shield over the character.

On the C++ part: Mesh->GetAnimInstance() returns the actual object, not the UClass. What USkeletalMeshComponent::SetAnimInstanceClass expects is actually the TSubclassOf< UAnimInstance > or in UAnimInstance::StaticClass()

That being said, I think you are looking for something else though. If I understand you correctly, you want to drive more than one mesh with the same animation data, right? Like a modular Pawn.

I think you are looking for USkinnedMeshComponent::SetMasterPoseComponent

Actually this article might help you.

Yes, and I’ve edited my post to further reflect that. I’m going to try out that article now, thankyou.

Edit: That article is horribly outdated, but this works perfectly

//.cpp constructor
    	Mesh2 = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Mesh2"));

Makes me wonder why this post I made a long time ago never got a straight answer when the solution is so simple. :s