How to create a Montage and play it in C++?

The title is pretty much it.
This is what I have:

UAnimMontage* UCpp_BPFL_Animate::Cpp_BPFL_Animate_PlaySlotAnimation(
	UAnimInstance* AnimInstance, 
	UAnimSequence* AnimSequence,
	FName SlotNodeName, 
	float BlendInTime, 
	float BlendOutTime, 
	float InPlayRate,
	bool bEnableAutoBlendOut
)
{
    if (!AnimSequence || !AnimInstance)
    {
        return nullptr;
    }

    UAnimMontage* NewMontage = NewObject<UAnimMontage>();

    if (NewMontage)
    {
        FSlotAnimationTrack SlotAnimTrack;
        SlotAnimTrack.SlotName = FName("DefaultSlot");

        FAnimSegment AnimSegment;
        AnimSegment.AnimReference = AnimSequence;
        AnimSegment.StartPos = 0;
        AnimSegment.AnimEndTime = AnimSequence->GetPlayLength();
        AnimSegment.AnimStartTime = 0;
        AnimSegment.LoopingCount = 1;

        SlotAnimTrack.AnimTrack.AnimSegments.Add(AnimSegment);

        NewMontage->SlotAnimTracks.Add(SlotAnimTrack);

        AnimInstance->Montage_Play(NewMontage, 1.0f);
    }

    return NewMontage;
}

The idea is to input an AnimSequence, transform it into a Montage, edit all the necessary values and then play it.

But no matter what I try I can’t get it to work…

I made a new post with more details and an answer.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.