‫Hello and welcome.
‫In this lecture, we are going to introduce you to a new part of the animation blueprint called a state
‫machine.
‫Very useful part of it.
‫And what it will allow us to do is if we hit a Boolean switch here, it's going to allow us to transition
‫into a jumping state and then back down to grounded.
‫Let's see how all of this works and how we can create this for ourselves.
‫Okay.
‫So we've got this really weird behavior when we jump, which just means that we end up running in midair,
‫which is obviously not a very good look.
‫Now, to fix this, we're going to need to learn about a whole new animation concept called an animation
‫state machine.
‫So this belongs in the animation blueprint.
‫So go ahead and get that fired up if you haven't got it fired up already.
‫And over in the anim graph, so far everything we've done in the graph has been through these nodes
‫here.
‫Now, what I want to show you is how we can add something new, something called a state machine.
‫We're going to right click and this is in the anim graph and we're going to look for state machine.
‫And you can see that this ad, new state machine is one option here.
‫Now, I want to show you that there's another way of doing this as well.
‫If you right click all the way back.
‫So if we right click in the anim graph and search for new state machine, then we've got this option.
‫Here we click, it creates a new node and you can see that node has a single animation PO's output pin
‫and over in the left hand pane in the My Blueprint, it's created this new state machine underneath
‫our anim graph.
‫So if you either double click on the new state machine or click it over in the anim graph, you see
‫it takes you to this new window.
‫So it's yet another thing.
‫We've got our anim graph, our event graph, and now we've got this state machine graph.
‫We can actually rename that.
‫So we can give our state machine a better name by clicking it in the My Blueprint and hitting two.
‫And we can call it locomotion because this is going to be all about locomotion.
‫And then what does a state machine do?
‫Well, a state machine is at its simplest, it's a set of if you right click.
‫In fact, you can see there's a couple of options here.
‫There's a comment, there's a conduit.
‫But the most important thing is it states it is a machine full of states.
‫And I can add a couple of states in here to give you an idea.
‫So we've got state, state one, state two.
‫And then if you drag off of this border, it creates something called a transition.
‫So you can create a transition between states.
‫And we've got this entry pin which basically is telling us where which state should be started.
‫Okay.
‫So let's take a little step back.
‫What does this all mean?
‫Well, in each given state, if you double click on it, you can see that there is an output pin and
‫that output pin can be used in the same way as our anim graph can be used to build up an animation pose.
‫So in its simplest form, we might just decide to stick an animation in here.
‫So select any old animation playability, for example.
‫And that's the animation that's going to be played when the state machine is in a given state.
‫Now, how do we get into a given state?
‫Well, we might get into a given state because our entry node points to it.
‫And so that's the default state.
‫That's where we start off.
‫But then we might get to a state via a series of transitions as well.
‫So the transitions each have properties, you can double click on a transition and you can see that
‫again.
‫We get this node editor pop up and we can have some sort of boolean property.
‫So I don't know we could have some thing like is dead, we can get is dead we can pipe that into here
‫and now every time is dead is true.
‫We're going to make the transition if we're in this original state, if we are dead, then we'll make
‫the transition into state one and we'll start playing the animation in State one.
‫And then if the transitions from State one are true, for whatever reason, we might make the transition
‫over to State two.
‫Okay, so this is all very well and good in theory, but how does this help us in practice with running?
‫Well, for example, we might want a state that says grounded.
‫And in the grounded state, we're going to play our ground locomotion.
‫So if we go back up to our anim graph, what is our grounded locomotion?
‫It is basically everything here.
‫Before the we add our idle combat offset, there's this locomotion blend space is our grounded offset.
‫So I'm going to cut the nodes here, go and hook up my locomotion state machine to pass in to our aim
‫offset.
‫Then I'm going to go into the locomotion state machine, go into the grounded state and paste in those
‫nodes here and connect them up to the output pin.
‫So let's follow what's going on here at the anim graph level.
‫First of all, we are running the animation locomotion state machine.
‫And because I haven't hooked this up, but because the entry pin points to the grounded state, we're
‫automatically in the grounded state, it's going to go into there, figure out, okay, we've got a
‫blend space, we blend it using our variables, then we output this.
‫That becomes the output of our state machine as a whole.
‫And then it feeds through into the combat animation, which feeds through into our death animation,
‫which feeds into our final output.
‫So hopefully now what we'll see when we compile it is actually nothing really has changed because there's
‫only one state in our state machine.
‫However, if we're jumping then we can introduce a new state.
‫For that we go ad state, then we can have airborne as a state, and in this state we won't be playing
‫the same animations.
‫We're essentially switching out those animations in the anim graph up.
‫At this level, we're saying that this node is going to switch to playing different animations when
‫in the Airborne State.
‫So we want to go into the Airborne State and make sure we have an animation selected here.
‫So I'm going to pull off of that result pin and I'm just going to look for a jump.
‫And particularly I'm going to look for the jump apex combat combat because that has as aiming Apex because
‫this will be the top of our jump and then we're going to go out of the anim graph, then we're going
‫to go out to the locomotion level and we'll notice that there's a problem here.
‫There's no way for us to get to the Airborne State because there isn't a transition that leads us there.
‫So what we want to do is drag from the border of grounded on to the airborne state and we want to double
‫click in there because we want to create a transition here.
‫And I'm just going to do a transition based on a variable which we don't currently have.
‫So if I go over to my blueprints, add a variable and have an is airborne as a boolean variable in here,
‫then I can pull that over in to this node editor for our grounded transition.
‫And then we can hook that up so that what we're saying is this transition is possible when we are airborne
‫and then we want a converse transition that goes from airborne to grounded.
‫And if we click on double click on that one, then we can put in a knot node which basically negates
‫the boolean and then we can put in the is airborne boolean as well.
‫So that at the end what we've got here, if we go to our anim preview editor tab over to the right,
‫we can flip this switch and we go into that airborne state playing the airborne animation.
‫And if we flip it again, we go back in to our grounded locomotion and you can see that all of this
‫is going to be working with our aim pitch as well.
‫If I move the aim pitch pointing up, then I hit an airborne.
‫You can see we keep aiming in the direction that we should be aiming.
‫Okay, so I've got a mini challenge for you, apart from getting the state machine set up like this,
‫if you haven't been following along already, what I would like you to try and do is see if you can
‫find a way.
‫At the moment when we click is airborne, we get this weird glitching looping of this animation, this
‫airborne animation.
‫See if you can make it so that this animation doesn't loop.
‫So if you can find your way around the anim blueprint, which can be quite hard to navigate and see
‫if you can find that property.
‫Welcome back.
‫So hopefully you've gone and given this a shot.
‫So where would we start to think about this?
‫How would we start to navigate around this blueprint?
‫Well, for a start, we know that this problem is coming from our locomotion state machine.
‫So let's go in there and we can see that the thing that is playing the state that's currently playing
‫is the airborne state.
‫So let's go into that and you can see that the jump apex combat is just looping round and round and
‫it's clearly creating this problem here.
‫So if we click on that animation and look at the details, you can see that we have got this loop animation
‫property set.
‫If I uncheck that and then recompile our animation blueprint, then I go and hit the is airborne.
‫You can see it plays that jump apex just once and then it proceeds to hold that animation until we uncheck
‫the box, at which point it transitions back to our locomotion state machine.
‫Let's see all of that working if we had a bit of speed, if we were moving.
‫So here we are running, we add our is airborne, it goes into our jump apex until we are no longer
‫airborne, at which point we transition back to being running on the ground.
‫So that's it for this lecture.
‫We've been introduced to a whole new concept, a lot to take in the idea of an animation state machine
‫we've seen about states and how we get into them via transitions, and we've seen how that can be driven
‫by a boolean value to allow us to have a jump state.
‫In the next lecture, we're going to hook this up to gameplay and refine things further.