Is it possible to play AnimSequence and AnimaMontage without AnimationBlueprint and use C++ only?

I want to play animation without blueprints, because I have too many Character Models to handle. If I use animation blueprint to handle animation playing, I have to edit BP one by one, and all logic of these Characters are the same, that’s very inefficient, so I want to find a way to play animation by programming.

I have read this post:
https://answers.unrealengine.com/questions/292345/how-can-i-play-animations-strictly-from-c.html

but GetMesh()->GetAnimInstance() return NULL. my code:


USkeletalMesh* Mesh_guijiao = LoadObject<USkeletalMesh>(NULL, TEXT("SkeletalMesh'/Game/Mannequin/pawn_guijiao_mesh.pawn_guijiao_mesh'"));
UAnimSequence* AnimSeqIdle = LoadObject<UAnimSequence>(NULL, TEXT("AnimSequence'/Game/Mannequin/pawn_guijiao_anim_attack01.pawn_guijiao_anim_attack01'"));
UAnimMontage* MontageIdle = LoadObject<UAnimMontage>(NULL, TEXT("AnimMontage'/Game/Mannequin/pawn_guijiao_montage_idle.pawn_guijiao_montage_idle'"));

AWarriorCharacter* Warrior = World->SpawnActor<AWarriorCharacter>(FVector(1500, 1500, 100), FRotator(0, 0, 0));
Warrior->GetMesh()->SetSkeletalMesh(pMesh);

UAnimInstance *AnimInst = Warrior->GetMesh()->GetAnimInstance();
if (!AnimInst)
{
	return false;
}
AnimInst->PlaySlotAnimationAsDynamicMontage(AnimSeqIdle, TEXT("DefaultSlot"), 0.1f, 0.1f, 1.0f, 5);

Depending on what class AWarriorCharacter* derives from, you’ll have to manually set its AnimInstance class using
SetAnimInstanceClass
(
UClass* NewClass
)

You can create a custom anim instance class that behaves the way you’d like it. And naturally, for every different character that has some behaviour in common, they should derive from a common base class which handles that specific part of their logic.

thanks for your support! you are right.