﻿1
00:00:04,610 --> 00:00:05,450
‫Hello and welcome.

2
00:00:05,450 --> 00:00:10,790
‫In this lecture, we're going to be hooking up our health system to the animation blueprint so that

3
00:00:10,790 --> 00:00:13,730
‫I can shoot this character until he dies.

4
00:00:13,730 --> 00:00:15,680
‫Let's dive in and see how that works.

5
00:00:16,520 --> 00:00:22,820
‫So we want this boolean in the animation blueprint to be set automatically from our gameplay.

6
00:00:23,090 --> 00:00:29,300
‫And if we go through to our event graph and have a look how this is currently working, other properties

7
00:00:29,300 --> 00:00:34,460
‫like this, such as get velocity, get active, transform, we're going to the pawn and we're doing

8
00:00:34,460 --> 00:00:38,480
‫a get function on it every time we want to update our animation.

9
00:00:38,750 --> 00:00:43,970
‫So we want to kind of follow along in this model where we're going to go and get whether or not our

10
00:00:43,970 --> 00:00:45,180
‫player is dead.

11
00:00:45,200 --> 00:00:52,400
‫So to do that, we need to expose some functionality, some callable function from our C++.

12
00:00:52,520 --> 00:00:57,140
‫So let's go over to the C++ and have a look what is there.

13
00:00:57,140 --> 00:01:02,540
‫So we've could create a public function, but that doesn't necessarily make it accessible.

14
00:01:03,050 --> 00:01:10,040
‫To do the accessibility, we need to have a U function which makes it visible to blueprint and unrolls

15
00:01:10,040 --> 00:01:11,030
‫header tool system.

16
00:01:11,030 --> 00:01:15,080
‫But we've got to go one step further than just having it as a you function.

17
00:01:15,080 --> 00:01:20,150
‫So we start with the you function macro, but we want to make it blueprint callable.

18
00:01:20,150 --> 00:01:23,180
‫So that is the option that we can use blueprint callable.

19
00:01:23,990 --> 00:01:30,170
‫However, there is another option that overrides Blueprint or rather implies that it's blueprint callable

20
00:01:30,170 --> 00:01:32,460
‫and that is blueprint pure.

21
00:01:32,480 --> 00:01:36,830
‫Now we'll see the difference between blueprint pure and Blueprint callable in just a second.

22
00:01:36,830 --> 00:01:43,430
‫But just know that if you use Blueprint Pure, it is doing the same as Blueprint Callable and then some.

23
00:01:43,430 --> 00:01:45,650
‫So it's doing a little bit more than Blueprint callable.

24
00:01:46,070 --> 00:01:50,660
‫And then what we want is a function that returns Boolean that says whether or not this character is

25
00:01:50,660 --> 00:01:51,410
‫dead.

26
00:01:52,290 --> 00:01:54,440
‫That is going to be useful for us to know.

27
00:01:54,450 --> 00:01:58,740
‫And then finally, we want this to be a concert member function.

28
00:01:58,770 --> 00:02:00,810
‫Now, why does it want to be concert?

29
00:02:00,810 --> 00:02:07,470
‫Because when we call this function, we don't expect it to change any of the state of our shooter to

30
00:02:07,470 --> 00:02:08,040
‫character.

31
00:02:08,040 --> 00:02:12,030
‫So we can safely say that this should be a concert function.

32
00:02:12,150 --> 00:02:19,800
‫And in actual fact, concert and blueprint pure often go together because blueprint pure means that

33
00:02:19,800 --> 00:02:24,330
‫if we go over in to any blueprint, we can have a look at some pure nodes.

34
00:02:24,330 --> 00:02:26,130
‫This one here get act transform.

35
00:02:26,130 --> 00:02:27,030
‫That's a pure node.

36
00:02:27,030 --> 00:02:30,720
‫Get velocity is a pure node set speed is not a pure node.

37
00:02:30,720 --> 00:02:33,330
‫Can you see what might be linking these together?

38
00:02:33,330 --> 00:02:37,380
‫What about these makes this not pure and this one pure?

39
00:02:37,410 --> 00:02:40,800
‫Well, generally speaking, it's the fact that there's an execution pin.

40
00:02:40,800 --> 00:02:44,970
‫A pure node is one that doesn't have an execution pin.

41
00:02:44,970 --> 00:02:51,330
‫And it's usually safe to say that something doesn't have an execution pin when it doesn't have any impact

42
00:02:51,330 --> 00:02:54,210
‫on the thing that it's calling only on its result.

43
00:02:54,270 --> 00:03:00,330
‫Essentially, this means that no matter how many times we call this function, it's going to always

44
00:03:00,330 --> 00:03:01,620
‫output the same result.

45
00:03:01,620 --> 00:03:05,160
‫It's always going to have the same effect on the program.

46
00:03:05,160 --> 00:03:06,720
‫It's as a pure function.

47
00:03:06,720 --> 00:03:09,240
‫It doesn't change anything when it is called.

48
00:03:09,240 --> 00:03:14,670
‫So it's kind of the same as constant, although it's a little bit stronger because what it's saying

49
00:03:14,670 --> 00:03:20,250
‫is not just that it doesn't change anything here on the shooter character, but it doesn't change anything

50
00:03:20,250 --> 00:03:22,020
‫global, any state anywhere.

51
00:03:22,020 --> 00:03:22,890
‫Full stop.

52
00:03:22,890 --> 00:03:28,980
‫The only input, the only effect it has is in the outputs that it produces.

53
00:03:29,580 --> 00:03:32,340
‫So that's why we're choosing to make this blueprint pure.

54
00:03:32,340 --> 00:03:37,170
‫It removes the need for an execution pin, which makes it much nicer in blueprint.

55
00:03:37,170 --> 00:03:43,170
‫And it also just expresses the fact that we aren't making any changes to the state of our game when

56
00:03:43,170 --> 00:03:44,340
‫we call this function.

57
00:03:44,520 --> 00:03:48,660
‫So let's go ahead and try to create an implementation for this.

58
00:03:48,660 --> 00:03:54,180
‫In fact, I'm going to leave the implementation up to you as a challenge, and we're going to go over

59
00:03:54,180 --> 00:04:00,060
‫and hook this up in an anim graph, sorry, an event graph of the animation blueprint.

60
00:04:00,210 --> 00:04:03,810
‫So we're going to do this by having a new set here.

61
00:04:03,810 --> 00:04:12,720
‫We want to set the is dead boolean variable at the end and we want to get the pawn owner and we want

62
00:04:12,720 --> 00:04:18,660
‫to cast that because it needs to be a shooter character in order to have this is dead property.

63
00:04:18,660 --> 00:04:23,430
‫So we want to cast it to and in this case I want to cast it to the C++ shooter characters because I

64
00:04:23,430 --> 00:04:28,260
‫don't need to go all the way down to saying it's definitely a blueprint version of this because this

65
00:04:28,530 --> 00:04:31,650
‫new function actually exists on the C++ level.

66
00:04:31,650 --> 00:04:33,510
‫So we're going to go ahead and cast.

67
00:04:33,510 --> 00:04:36,930
‫If we succeed in cast, we're going to be setting the is dead property.

68
00:04:37,110 --> 00:04:42,690
‫And let me just put in some redirect nodes here to make our blueprint just a little bit nicer looking

69
00:04:42,690 --> 00:04:43,650
‫like so.

70
00:04:44,070 --> 00:04:47,610
‫And then what we want to do is using this shooter character reference.

71
00:04:47,610 --> 00:04:52,980
‫Now that we've cast it to a shooter character, we know that it should have this is dead property.

72
00:04:52,980 --> 00:04:54,900
‫So we should be able to do that.

73
00:04:55,080 --> 00:05:00,180
‫Once you've compiled and got it working, you can get this is dead property and set it here.

74
00:05:01,080 --> 00:05:04,860
‫This it's time for your challenge to calculate if we are dead or not.

75
00:05:04,860 --> 00:05:08,220
‫So return the correct boolean out of our is dead function.

76
00:05:08,220 --> 00:05:09,180
‫That's the first step.

77
00:05:09,180 --> 00:05:15,750
‫You might want to use some inequalities with our health variable for that and then hook up our variable.

78
00:05:15,750 --> 00:05:20,310
‫The dead is dead variable in the animation blueprint we got just short of doing that.

79
00:05:20,310 --> 00:05:23,490
‫We just needed we were just basically a compile away from getting that done.

80
00:05:23,490 --> 00:05:26,280
‫Pause the video and get that sorted.

81
00:05:27,520 --> 00:05:27,790
‫Okay.

82
00:05:27,790 --> 00:05:28,340
‫Welcome back.

83
00:05:28,360 --> 00:05:31,840
‫So let's go over to the code, first of all.

84
00:05:31,840 --> 00:05:36,730
‫So this fairly straightforwardly, I'm going to return an expression that returns a boolean.

85
00:05:36,730 --> 00:05:43,450
‫So we want to say, is the health less than or equal to zero, in which case we are indeed dead?

86
00:05:43,510 --> 00:05:47,710
‫That's about as simple as a an expression of function can get.

87
00:05:47,710 --> 00:05:49,990
‫So let's go ahead and build that.

88
00:05:50,680 --> 00:05:55,600
‫And once that has compiled, we can go over into Unreal and hook it up.

89
00:05:55,600 --> 00:06:02,020
‫So dragging off the as shooter to character, we are node we're going to have a shooter character reference

90
00:06:02,020 --> 00:06:08,470
‫here so we want to do is dead gives us this is dead function you can see it has no execution pin because

91
00:06:08,470 --> 00:06:09,550
‫it is pure.

92
00:06:09,580 --> 00:06:15,010
‫Then we take this boolean off of that and hook it up to our is dead variable.

93
00:06:15,130 --> 00:06:21,340
‫And now if we go ahead and play, we should actually be able to kill off that character in the world.

94
00:06:21,340 --> 00:06:24,190
‫We'll shoot at him until his health goes down to zero.

95
00:06:24,190 --> 00:06:25,300
‫And there you go.

96
00:06:25,300 --> 00:06:28,780
‫The animation has successfully killed him off.

