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)