Unreal - How to use Montages




Howdy! So I've been working on an fps attack animation system, In particular, I needed to emulate a specific game I like very much Called Vermintide, that I mentioned in a previous post.

My first post was simply me establishing how I an an individual could modularize animation creation enough so that it would be easy to add in new attacks. I focused on just deciding on the workflow I wanted to use.

Now I want to see my combat in game - I need code in my Combat animations. And I want them to be as close as possible to Vermintide combat (for now).

How do I replicate this engaging combat? There's a couple of key notes; Attack happen in sequences. There attack repeatedly triggers new attack animations. Each of these animations is it's own type of attack style (sweep, bludgeon, etc) with a specific hit pattern to match.

I need a better example, but the point is you can switch attacks and to defense quickly

How does this animation work? After creating the pawn, animation, and input BPs, I tried to make a system using the state machine. Unfortunately, this had issues.

Part 1: using Sequences with State Machine (not good)

The idea is that in animations sequence assets, you add notifies. These notifies call events, that then set values in the pawn BP to reset booleans for attacking, enums for attack type, etc. This however, appeared to created race conditions that would freeze the animation with too much input. This makes sense considering that Animation BPs are hard to optimize

I started by making all of the options Different States. The animations had notifys.

These Notifies were attached to events in the graph which called functions in the Pawn. The pawn would set/reset values.

This did not work well; Not only is my state machine increasingly complex, clicking rapidly creates a race condition. This would not work in the long haul.

It's best to keep Animation BPs as simple as possible; they are taxing and may not be thread safe, or otherwise update well with other BPs. Anim BPs should only read in data from other bps and be dependent on it.

But I wanted metadata attached to my animations; I COULD build a system that tracks the animation time independently, but I don't see the point in that. This is where I learned the beauty of montages.

What I learned is that the state machine should be used for more passive actions; that is, state should be attached to animations that run in parallel to player input; but are not directly activated by player input, if that makes sense.

Part 2: Using Montages

Montages are animations that are played in montage slots in the animation BP. In most cases, they are used to play additive animations, like playing a punching animation while running.
When you play a montage from a BP, it plays in a slot in the animBP.
To play a montage, call one of these two functions in a BP. Notice the top one comes from character. Every dolt on YouTube decides that's the one they're gonna tell you about. To be fair, the top one has an advantage we'll mention later.

There are three particular parts of a montage asset worth noting:
  1. Montage Section: You can break up your animation sequence into different sections. You can re-arrange the order sections are played in the Section Tab to the right. Then in the BP, call them by name.
  2. Montage Slots: You can pass animations to more than one slot in a montage. To do this, add another slot here. You can then Add or move animations around (albeit I have found you need to re-open the file to see the results render correctly)
  3. Notifies: Here we can add the notifies called by this. You can also add notifies to a normal sequence, but here we have the advantage of calling a Montage Notify. this passes the notify name to the BP it was called from, and from which we can append code to.
3 parts; sections, slots, and notifies.
Inside the BP the montage was called in, I can switch functions based on montage notify name.

So, now I have an ability to get data from the animation I'm playing, like when an attack begins, or ends, and so on. I can use this to quickly resent my input for attacking. I can attack, and if I don't attack again, the animation for the player returning to idle plays smoothly through - if I do attack again, I can smoothly transition to the next attack without delay. I can also pass when the attack happens for gameplay purposes

When I attack, I have a function to determine what current montage I want to play. I then pass this to a montage event. How I determine this is in another post.
What's really cool is that I can also condense my animation files; no need to save/ re-create a bunch of files, I can simply have all of my attack animations sectioned in a single file! very neat. There are a few caveats however.

Back to the Animation BP briefly; now I can have a very simply state machine for First person. I do make a specific state for when I'm playing a montage, to make transitions back to idle smoother. If I don't, the montage will end and the idle state will start with no transition. There is probably a better way to do this but this is it for now.
Inside the montage stage I have the montage slot.

That's about it! Now we have fluid montage animations, that I can set based on the weapon.

Comments

Popular posts from this blog

Unreal - First Post!!! and Creating an animation workflow in engine

Unreal - Structing my weapon Creation workflow (WIP)