How to use Montage Set Next Section to end an idle loop correctly?

I feel like I am missing something obvious, but here is what I want to happen:

1. Have a montage with 3 sections: an Intro, an Idle, and an Outro.

2. When the montage starts, it plays the Intro, then goes into looping the idle until some other part of the code decides the NPC is done with this behavior.

3. When (or I guess technically right before/as) the montage ends, play the Outro section.

An example scenario would be having an NPC sit in a chair. They need to play the intro animation for sitting down into it. Then a looping idle while sitting. Then a “standing back up” anim when the sitting behavior is interrupted or called as finished in some way.

I currently have points 1 and 2 working. The Idling section is set up to loop in on itself in the Montage Sections:

My issue/question is getting #3 to work.

From research I found the “Montage Set Next Section” node, whose tooltip even cites this scenario

I can get it to work if I hook it up right after the Play Montage node (for the purposes of just proving to myself it works at all and I’m passing through all the right data), like so:

However, obviously, this doesn’t accomplish what I need, because of course it will fire off right when the Play Montage node is called, which means my Idle loop plays once then goes immediately to the Outro and the montage is finished. But I need to accommodate situations where the NPC needs to run the Idle for an indefinite amount of time, until some external event (such as in its AI behavior) says “ok stop this now and do something else”.

For testing purposes I press a debug key to call Stop Anim Montage, which triggers the On Interrupted output of Play Montage. Problem is, once this happens, (I think) the montage considers itself “done”, and so running Montage Set Next Section after this is pointless because the Outro will never play.

The only hacky workaround I can think of is just break the Outro animation out into its own montage and play that manually after On Interrupt in the BP. But that feels clunky and also like it’s sort of sidestepping what Montages were designed for? Any suggestions appreciated.

In my idle/furniture system, I name the final section of all the looping montages to “end” (outro would work too, just be consistent), then when I want a character to stop sitting/dancing/whatever, I send an interface message to the actor which runs a function that gets the current montage, and feeds it to a MontageJumpToSection node.

1 Like

Thank you for the reply! I did end up implementing it this way and it works. I’m still a bit new to UE and so this was a good push to get me thinking in terms of interfaces.

However, want to also add for those who find this post in the future, I think the original issue in my logic was one that could be solved without interfaces (in case someone doesn’t want to use that method for whatever reason).

Namely, I was trying to use the “Montage Set Next Section” on a basic reference to the montage from data, when what I needed to be doing was getting a ref to the currently playing instance of my montage using Get Current Montage, as shown in @illspiritx 's solution.

You’re welcome. Yea, the interface stuff isn’t exactly necessary to make it happen, the important part, as you said, was getting the current montage from the anim instance.

In case you, or anyone else who comes across this is wondering, my reason for using JumpToSection instead of set next is so that it would end immediately. For example, I call the interface function to end the idle/furniture anims whenever a player or npc attacks, and don’t want to worry about a long loop segment finishing. Could do this by calling the function within the character without an interface too, but interface is handy when communicating between pawn, controller, and behavior tree tasks.

1 Like

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