How can I play animations strictly from C++?

I apologize for barging in, but as this thread comes up in searches, I thought I should chime in with what I learned through trial and error. The example below is not complete, but should help pointing in the right direction, hopefully.

There is a minimum required tinkering with non-C++ blueprints, but in my approach I tried my best to “set it and forget it”. If there are better ways, please share :slight_smile:

This is how my montage looks like, just two empty slots, I handle their population through C++

this is how my anim graph in my custom animation instance looks like

Inside each state machine I connected a dummy empty state to the entry point, not shown in this picture, but you get the gist of it.

This is my C++ code snippet to handle fetching animation sequences on the fly and assign them to the montage slots. please note that I’m using some custom functions I wrote that are not shown in the code below

for (int32 l = 0; l < oCreature->AnimMontage->SlotAnimTracks.Num(); l++)
			{
				FSlotAnimationTrack slot = oCreature->AnimMontage->SlotAnimTracks[l];
				if (slot.SlotName.ToString().Contains("LowerBody"))
				{
					FAnimSegment NewSegment;
					NewSegment.AnimReference = oCreature->AnimSequence;
					NewSegment.AnimStartTime = animationListList.AnimationList[j].StartTime;
					NewSegment.AnimEndTime = oCreature->AnimSequence->SequenceLength;
					NewSegment.AnimPlayRate = animationListList.AnimationList[j].Speed;
					NewSegment.LoopingCount = 1;
					NewSegment.StartPos = animationListList.AnimationList[j].StartOffset;

					slot.AnimTrack.AnimSegments.Add(NewSegment);

					oCreature->AnimMontage->SlotAnimTracks[l] = slot;
					break;
				}
			}
		}
	}
}

as I mentioned, the example above is not either complete or fully functional out-of-the-box, but hopefully should help…