How can I play a montage for x seconds?

I am working on a combat system and I want to implement parries by having the character take a stance, then exit the stance after some time. If they are attacked while in that stance they will parry the attack. I actually have everything figured out, except the stance animation part.

How do I run a montage that loops for x seconds? Is this possible or do I have to make the animation itself run the duration I want?

Im hoping for a flexible play time so I can have characters with different parry windows and to make it easy to adjust and balance in the future.

Is a montage really needed for this?

There aren’t many dials to work with on a montage for this, you can set a start offset and the play rate, which I guess might go some way (but possibly with unacceptable side effects).

Best bet would probably be to manage the timing yourself and get out of the montage with Stop Anim Montage when the time comes.

But from what I can tell, better still would be to ditch the montage, just set and control a Is Parrying var on the character, and access it (and respond appropriately when true) from your animation graph like normal.

1 Like

Im using montage to keep things consistent, since all my attacks are montages. I use the anim graph only for locamotion states.

Using stop montage seems like it might be my best bet. Or i can utilize montage sections to repeat it till a timer runs out.

Here is my solution:

I extended my stance montage to contain 3 sections. An enter stance section (Default), the stance section, and an exit stance section where the character goes back to its idle pose.

Then I set the montage to loop the stance section.

From there I play the montage in the character BP, but when its played I also trigger a delay for the amount of time I want the stance held. Once the delay is up I skip to the exit section.
Screenshot 2024-07-09 232806

I didn’t try but I suspect this could be done similarly with a montage that only contains one looping section. Then, after the delay, you would just stop the montage or play another.

1 Like