‫Hello and welcome.
‫In this lecture, we're going to be hooking up our health system to the animation blueprint so that
‫I can shoot this character until he dies.
‫Let's dive in and see how that works.
‫So we want this boolean in the animation blueprint to be set automatically from our gameplay.
‫And if we go through to our event graph and have a look how this is currently working, other properties
‫like this, such as get velocity, get active, transform, we're going to the pawn and we're doing
‫a get function on it every time we want to update our animation.
‫So we want to kind of follow along in this model where we're going to go and get whether or not our
‫player is dead.
‫So to do that, we need to expose some functionality, some callable function from our C++.
‫So let's go over to the C++ and have a look what is there.
‫So we've could create a public function, but that doesn't necessarily make it accessible.
‫To do the accessibility, we need to have a U function which makes it visible to blueprint and unrolls
‫header tool system.
‫But we've got to go one step further than just having it as a you function.
‫So we start with the you function macro, but we want to make it blueprint callable.
‫So that is the option that we can use blueprint callable.
‫However, there is another option that overrides Blueprint or rather implies that it's blueprint callable
‫and that is blueprint pure.
‫Now we'll see the difference between blueprint pure and Blueprint callable in just a second.
‫But just know that if you use Blueprint Pure, it is doing the same as Blueprint Callable and then some.
‫So it's doing a little bit more than Blueprint callable.
‫And then what we want is a function that returns Boolean that says whether or not this character is
‫dead.
‫That is going to be useful for us to know.
‫And then finally, we want this to be a concert member function.
‫Now, why does it want to be concert?
‫Because when we call this function, we don't expect it to change any of the state of our shooter to
‫character.
‫So we can safely say that this should be a concert function.
‫And in actual fact, concert and blueprint pure often go together because blueprint pure means that
‫if we go over in to any blueprint, we can have a look at some pure nodes.
‫This one here get act transform.
‫That's a pure node.
‫Get velocity is a pure node set speed is not a pure node.
‫Can you see what might be linking these together?
‫What about these makes this not pure and this one pure?
‫Well, generally speaking, it's the fact that there's an execution pin.
‫A pure node is one that doesn't have an execution pin.
‫And it's usually safe to say that something doesn't have an execution pin when it doesn't have any impact
‫on the thing that it's calling only on its result.
‫Essentially, this means that no matter how many times we call this function, it's going to always
‫output the same result.
‫It's always going to have the same effect on the program.
‫It's as a pure function.
‫It doesn't change anything when it is called.
‫So it's kind of the same as constant, although it's a little bit stronger because what it's saying
‫is not just that it doesn't change anything here on the shooter character, but it doesn't change anything
‫global, any state anywhere.
‫Full stop.
‫The only input, the only effect it has is in the outputs that it produces.
‫So that's why we're choosing to make this blueprint pure.
‫It removes the need for an execution pin, which makes it much nicer in blueprint.
‫And it also just expresses the fact that we aren't making any changes to the state of our game when
‫we call this function.
‫So let's go ahead and try to create an implementation for this.
‫In fact, I'm going to leave the implementation up to you as a challenge, and we're going to go over
‫and hook this up in an anim graph, sorry, an event graph of the animation blueprint.
‫So we're going to do this by having a new set here.
‫We want to set the is dead boolean variable at the end and we want to get the pawn owner and we want
‫to cast that because it needs to be a shooter character in order to have this is dead property.
‫So we want to cast it to and in this case I want to cast it to the C++ shooter characters because I
‫don't need to go all the way down to saying it's definitely a blueprint version of this because this
‫new function actually exists on the C++ level.
‫So we're going to go ahead and cast.
‫If we succeed in cast, we're going to be setting the is dead property.
‫And let me just put in some redirect nodes here to make our blueprint just a little bit nicer looking
‫like so.
‫And then what we want to do is using this shooter character reference.
‫Now that we've cast it to a shooter character, we know that it should have this is dead property.
‫So we should be able to do that.
‫Once you've compiled and got it working, you can get this is dead property and set it here.
‫This it's time for your challenge to calculate if we are dead or not.
‫So return the correct boolean out of our is dead function.
‫That's the first step.
‫You might want to use some inequalities with our health variable for that and then hook up our variable.
‫The dead is dead variable in the animation blueprint we got just short of doing that.
‫We just needed we were just basically a compile away from getting that done.
‫Pause the video and get that sorted.
‫Okay.
‫Welcome back.
‫So let's go over to the code, first of all.
‫So this fairly straightforwardly, I'm going to return an expression that returns a boolean.
‫So we want to say, is the health less than or equal to zero, in which case we are indeed dead?
‫That's about as simple as a an expression of function can get.
‫So let's go ahead and build that.
‫And once that has compiled, we can go over into Unreal and hook it up.
‫So dragging off the as shooter to character, we are node we're going to have a shooter character reference
‫here so we want to do is dead gives us this is dead function you can see it has no execution pin because
‫it is pure.
‫Then we take this boolean off of that and hook it up to our is dead variable.
‫And now if we go ahead and play, we should actually be able to kill off that character in the world.
‫We'll shoot at him until his health goes down to zero.
‫And there you go.
‫The animation has successfully killed him off.