Ok, going to make some corrections and going over basics:
- You need an animation blueprint to be present.
- In the animation blueprint you need a slot node going into the final pose. The default one is fine (DefaultGroup.DefaultSlot).
-
If you want your character to default to ‘Idle’ if nothing is happening, you can connect “Play Idle” to the default slot but it’s not necessary.
-
In code you can play a montage into that default slot:
a) You need a UPROPERTY where you can specify the Montage:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Anim)
UAnimMontage *MyMontage;b) In the Montage make sure it plays into the slot you specified (DefaultGroup.DefaultSlot is the default which should be fine)
c) Play the Montage:
if (MyMontage->IsValidLowLevel())
{
USkeletalMeshComponent *Mesh = GetMesh();
if (Mesh)
{
UAnimInstance *AnimInst = Mesh->GetAnimInstance();
if (AnimInst)
{
AnimInst->Montage_Play(MyMontage);
}
}
}
OR
a) Declare your montage variable in your header file:
UPROPERTY() // not absolutely necessary but highly recommended
UAnimMontage *MyCMontage;
b) In the constructor, load the montage:
static ConstructorHelpers::FObjectFinder<UAnimMontage> MyCMontageObj(TEXT("/Game/ThirdPerson/Animations/ThirdPersonWalk_Montage"));
MyCMontage = MyCMontageObj.Object;
c) Play the montage as before

