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)