Playing with animations in UE4
This post isn’t really attached to any of my modules in particular as it’s something I’m using in pretty much any assignment that utilises UE4, however, I felt like it’s good to write about my progress anyway.
I’m no animator, especially not one who can rig meshes and create awesome-looking animations like those seen in Assassin’s Creed or Uncharted, however that doesn’t stop me from knowing how to play around with them in-engine.
Like I said, I’m no animator, so I need to source my animations from elsewhere. The default ones that come with UE4 are great and are all really great for prototyping but they don’t offer that visual flair that I was looking for (I should point out that the example I’m using in this post will be hostiles from my XB2001 assignment).
That’s where Mixamo comes in. It’s a lifesaver - for those that don’t know it, it’s a site that offers free character meshes complete with skeletons and a lot of animations to play with. They can be imported into Unreal and pretty much any other engine that I can think of quite easily. You can customise details of the animations, too, some of which will be about positioning of certain limbs, the speed of limb movement, how many keyframes the animation has, where the animation has the character staying in place or not and so on.
I downloaded a bunch of zombie meshes from it along with animations to match and brought them all into UE4.
Setting Up the Animations:
When importing a mesh into UE4 it always offers to build a skeleton and a physics asset out of that mesh which is really handy as a mesh with no skeleton cannot be animated. For me, everything went quite smoothly.
Here’s one of the zombies in all her T-pose glory. The next bit was the hard part - I needed to create a way for the engine to know what animations to play, when to play them, and what order it should do them in. For something like this in programming we’d use state machines and it’s no different in this instance, but instead of playing with AI behaviours or camera logic, I’d be using animations.
Now that the engine has a bunch of animations it can play, it just needs to know one more thing. If the zombie was to walk, it’d move but its idle animations would still play. The fix to this is pretty straightforward - we need to tell it that once the pawn that possesses this animation blueprint moves at a certain speed, play the walk or run animations. We’d do that partially in the state machine and partially in the animation blueprint.
Now that we’ve gotten the pawn’s speed and direction and have set those values, the engine will know what to do on its end. The only thing left is blend space - without it, the engine will just snap to the next animation very suddenly and jarringly, it looks horrid. Blend spaces are there to fix that. The programmer in me found them really interesting so I’m going to enthuse about them a little bit, so don’t mind that!
A blend space is something that blends animations together, funnily enough. It adds a smooth transition between each one so that the skeleton of the mesh will have more natural movement once it switches to a new animation. When the default character in UE4 runs then stops, those are just 2 animations - run and idle. The blend space is what makes the transition between the two look incredibly smooth.
There are different kinds of blend space - 1D and 2D. The image above is a 2D blend space, this is what allows me to utilise direction. If you imagine that direct up from the centre is forward, then the lines either side are left and right, then both ends of the graph are backwards, that allows us to create a blend between animations that would involve strafing or running backwards and so on. 1D blend spaces allow us to create a much more linear graph that doesn’t utilise all of the above which is great for when you want to create a game that doesn’t need that many animations.
Mine technically doesn’t, but I want more experience with working with UE4′s animations, blend spaces, skeletons and so on.
There’s a lot more to show off, there’s a lot that one can do with animation blueprints and blend spaces. I’ll be working on them gradually over time because they aren’t a priority in any of my projects but they’re nice to have in anyway because they make the game feel more complete despite it just being a prototype.
https://imgur.com/0Gt7AIg (a gif to show the engine randomly choosing idle states for our zombie friend)