Setting Up Differening Animations Per Weapon in UE4 | Tech Discussion


This past week I began building upon the foundation I laid the week prior for how I would design our player's animation system. In short, the system works as follows:

  • An event occurs on the player blueprint that requires an animation (e.g. movement input)
  • The player blueprint sets a trigger on a component called AnimationTriggers  (think of this as "requesting" an animation)
  • The animation blueprint notices the trigger is set in  AnimationTriggers and modifies its internal variables accordingly
  • The animation state machine transisitions between animations in response to those modifications. 

In this way the player can request animations in a genericly without needing to know which particular animation file is being used, while also taking advantage of the state blending control the Anim Graph provides as well as neatly abstracting all state changing logic to one place. With this framework I was able to easily add a roll and step back mechanic  to the player that branched off of the main locomotion blend state. 

Now for this week I wanted to take this system and build our combat on top of it. The problem was that our combat animations could not simply be branched off the main blend state like rolling or jumping. The attack animations had to have the following features:

  • Combo attacks that play sequentially
  • Differing animation sets for heavy attacks and light attacks
  • Potentially differing combo counts between the heavy attacks and light attacks
  • Able to support completely different animations per weapon
  • Able to play recovery animation from any state if the player stops the attack
  • Fluid transitions for all everything

I started thinking about how this might be accomplished within the Anim Graph. Since animations were dependent upon the combo number and animation set, I knew the logical ordering for choosing an animation needed to be in a table like this...

...where the combo number and animation set can be used to index into the table to play the correct animation. A 2D blendspace seemed like the perfect way to go about this in Unreal, if it wasn't for the fact that combo numbers are discrete and it wouldn't be possible to blend between them. 

I played around with some designs in the Anim Graph, trying to find an organization that allowed for the adding of as many animation sets as we wanted. I came up with the following:

Here's a screenshot from Unreal but its harder to see so I'll be using the diagram instead

In this way I was easily able to maintain the "indexing" logic from the table above. For example, if I were to set the animation set to 1 and the combo number to 1, and then set an Attack trigger, the state machine would take the following path:

This design also allows for smooth transitioning between attacks like I wanted. Let's say I took the same path as above, but before the first attack ended I triggerd the next attack during a comboable window:

In this way I can also support recovering from any state by simply playing the entire attack with recovery animation in each state, only to interrupt them when the combo number changes. 

And of course, this design also provides for as many animation sets as we like, extending infinitely to the left:

The lines can get fairly messy, but that seems to always be a drawback with animation state machines. 

With the animation blueprint all set, all the player blueprint needs to do is handle input  to decide which which combo number and animation set to use (read from the currently equipped weapon).  

And that is how I set up differing animation sets per weapon in unreal.

Author: Reilly da Silva

Get Mythicism

Leave a comment

Log in with itch.io to leave a comment.