﻿1
00:00:04,550 --> 00:00:05,810
‫Hello and welcome.

2
00:00:05,810 --> 00:00:11,330
‫In this lecture, we are going to be starting to add even more functionality into our behavior tree

3
00:00:11,330 --> 00:00:17,210
‫by adding a custom task, this clear blackboard value, we're going to make that entirely custom in

4
00:00:17,210 --> 00:00:18,200
‫C++.

5
00:00:18,230 --> 00:00:20,240
‫Let's dive in and see how to do it.

6
00:00:21,280 --> 00:00:21,490
‫Okay.

7
00:00:21,490 --> 00:00:28,780
‫So I'd like to expand out the behavior of this behavior tree so that we can get to investigate.

8
00:00:28,780 --> 00:00:33,040
‫And once we're done investigating, we move on to going back home.

9
00:00:33,040 --> 00:00:40,240
‫So I'm going to add a little move to task here afterwards, which just returns us to the start location.

10
00:00:40,630 --> 00:00:47,140
‫And what we need to do in order to get there is to have some notion of whether we've already visited

11
00:00:47,140 --> 00:00:49,150
‫the last known play location.

12
00:00:49,210 --> 00:00:54,490
‫And the way I'm going to do that is essentially by setting the last known player location once we have

13
00:00:54,490 --> 00:00:57,820
‫investigated it now, if we don't currently have a way of doing that.

14
00:00:57,820 --> 00:01:00,910
‫But first of all, let's create the decorator.

15
00:01:00,910 --> 00:01:09,190
‫So add a decorator to investigating Blackboard that is going to be going to go and rename it to has

16
00:01:09,190 --> 00:01:16,630
‫investigated like so and this is going to check if the last known location is set.

17
00:01:16,750 --> 00:01:23,080
‫And that means that we need to have some sort of node that allows us to unset a blackboard key.

18
00:01:23,740 --> 00:01:25,300
‫Now that doesn't actually exist.

19
00:01:25,300 --> 00:01:26,650
‫You just thought it does, but it doesn't.

20
00:01:26,650 --> 00:01:31,360
‫So this is a great opportunity for me to show you how we can create a custom task.

21
00:01:31,360 --> 00:01:37,150
‫Now, you could do it very easily using Blueprint, or I'm going to show you the slightly harder way,

22
00:01:37,150 --> 00:01:41,050
‫but the one that gives you a lot of power, which is doing it through C++.

23
00:01:41,440 --> 00:01:48,970
‫So we're going to go over to our main content browser, go to add new and go to new C++ class and we're

24
00:01:48,970 --> 00:01:51,640
‫going to want to show all classes checkbox.

25
00:01:51,640 --> 00:01:56,950
‫And then we're searching for Beat Task and there's a lots of options here.

26
00:01:56,950 --> 00:02:03,760
‫You can see a lot of them are actually those built in tasks such as make noise or there is a move to

27
00:02:03,760 --> 00:02:04,900
‫here or wait.

28
00:02:05,110 --> 00:02:08,950
‫Now you could go and have a look at the C++ to see how those are implemented.

29
00:02:08,950 --> 00:02:13,720
‫That's always useful, but what we're interested in is what should we inherit from?

30
00:02:13,720 --> 00:02:17,200
‫What should we use as the basis for our own node?

31
00:02:17,260 --> 00:02:19,030
‫Now there's a couple of options here.

32
00:02:19,030 --> 00:02:25,420
‫You could choose to have a task node as your basis, or you could use the blackboard base.

33
00:02:25,420 --> 00:02:27,100
‫Now what's the difference between the two?

34
00:02:27,560 --> 00:02:28,630
‫Let's have a quick look.

35
00:02:28,630 --> 00:02:31,930
‫So move to actually uses the blackboard base.

36
00:02:31,930 --> 00:02:39,130
‫And what that means is that it has this blackboard key dropdown that allows us to choose a blackboard

37
00:02:39,130 --> 00:02:40,270
‫key to work with.

38
00:02:40,270 --> 00:02:45,940
‫That means we don't have to hard code into our task the blackboard keys that we're working with, which

39
00:02:45,940 --> 00:02:49,990
‫is great because it allows us to reuse those tasks in different situations.

40
00:02:49,990 --> 00:02:55,690
‫So if you need a blackboard key, then the blackboard base is a great one to go with, otherwise you

41
00:02:55,690 --> 00:02:56,710
‫use the other one.

42
00:02:56,710 --> 00:03:02,370
‫So let's go and add new add a new C++ class again, show all classes and we're looking for the beat

43
00:03:02,500 --> 00:03:06,910
‫task again and we're selecting the Blackboard Base hit next.

44
00:03:06,910 --> 00:03:15,850
‫Now I'm going to rename this to Beat Task, Underscore Clear Blackboard Value and we're going to go

45
00:03:15,850 --> 00:03:18,400
‫ahead and create that class here.

46
00:03:18,760 --> 00:03:20,470
‫Now, initially, this will fail.

47
00:03:20,470 --> 00:03:23,440
‫So let's click yes and see what the error message is here.

48
00:03:23,710 --> 00:03:29,800
‫It's saying something about Link, which stands for Link, unresolved external symbol, blah, blah,

49
00:03:29,800 --> 00:03:30,070
‫blah.

50
00:03:30,100 --> 00:03:35,590
‫Usually when you've got this kind of error from the linker, this is saying that you've got something

51
00:03:35,590 --> 00:03:43,030
‫in your header files that wasn't in your C++ or in this case it means that there isn't a module included

52
00:03:43,030 --> 00:03:44,860
‫that we are relying upon.

53
00:03:44,860 --> 00:03:52,030
‫And based on the types of symbols that it's looking for, I can see here it's the AI gameplay task owner

54
00:03:52,030 --> 00:03:52,750
‫interface.

55
00:03:53,020 --> 00:03:58,930
‫It seems to be looking for something to do with gameplay tasks and that is a module in actual fact.

56
00:03:58,930 --> 00:04:05,770
‫So if we go over to our Visual Studio code and just open up the file browser, it's just going to scroll

57
00:04:05,770 --> 00:04:07,300
‫up to my project.

58
00:04:07,300 --> 00:04:09,850
‫Then under source simple shooter.

59
00:04:09,850 --> 00:04:14,230
‫There should be a simple shooter build X or whatever your project name is, build.

60
00:04:15,040 --> 00:04:21,190
‫And in here, if I give us a little bit more space, you can see that we've got this public dependencies,

61
00:04:21,190 --> 00:04:29,740
‫module names and the module name here that we want to add to this list is going to be game play.

62
00:04:30,890 --> 00:04:37,430
‫Tasks with an S and if we go ahead and add that and go back and compile now, hopefully everything should

63
00:04:37,430 --> 00:04:40,070
‫compile successfully for whatever reason.

64
00:04:40,070 --> 00:04:44,680
‫This doesn't automatically get added when you override for a boot task.

65
00:04:44,690 --> 00:04:48,740
‫Now once that's done, let's go and have a look at what was created here.

66
00:04:49,040 --> 00:04:57,590
‫We should have a new class, which is our beta task, underscore clear blackboard value and it's pretty

67
00:04:57,590 --> 00:04:59,210
‫empty at the moment.

68
00:04:59,270 --> 00:05:05,150
‫Now what I want to do is if we were to add this in to our behaviour tree at the moment, it would have

69
00:05:05,150 --> 00:05:06,320
‫an ugly name.

70
00:05:06,320 --> 00:05:10,160
‫So we want a nice human readable name for this task.

71
00:05:10,160 --> 00:05:14,720
‫And the way we're going to do this is by adding in a constructor and setting a property.

72
00:05:14,720 --> 00:05:17,570
‫So let's create a public constructor here.

73
00:05:17,900 --> 00:05:21,620
‫The constructor always has the same name as the class so we can copy that.

74
00:05:21,750 --> 00:05:26,720
‫Doesn't need to take any arguments semicolon at the end and then let's create the implementation over

75
00:05:26,720 --> 00:05:28,190
‫in the C++.

76
00:05:28,520 --> 00:05:34,160
‫And the implementation just needs to set a variable called node name.

77
00:05:34,160 --> 00:05:40,580
‫So if you set node name and then you use a string, then the string that we set is going to be the node

78
00:05:40,580 --> 00:05:40,820
‫name.

79
00:05:40,820 --> 00:05:43,220
‫So it's going to be clear blackboard.

80
00:05:44,210 --> 00:05:48,730
‫Value just with the spaces and the correct capitalization should be nice and easy.

81
00:05:48,740 --> 00:05:54,240
‫Now, one thing that I forgot to do at the time of recording is to surround this by the text macro.

82
00:05:54,260 --> 00:05:58,880
‫Now you should go ahead and do that in your code, but you'll see that in my code.

83
00:05:58,880 --> 00:06:05,180
‫It will persist in just being like this, and we should be able to go and compile that now.

84
00:06:06,680 --> 00:06:09,170
‫Awesome that compiled successfully.

85
00:06:09,350 --> 00:06:12,170
‫So I challenge you to add this new node.

86
00:06:12,170 --> 00:06:17,050
‫So add it to the end of the investigation behavior and just check that it completes.

87
00:06:17,060 --> 00:06:21,470
‫Basically, it should automatically complete without doing anything at all.

88
00:06:21,470 --> 00:06:22,790
‫But check that the name is correct.

89
00:06:22,790 --> 00:06:26,270
‫Check that you're able to add it and we'll look at adding the behavior in the next lecture.

90
00:06:26,270 --> 00:06:27,560
‫So pause video and have a go.

91
00:06:28,730 --> 00:06:29,120
‫Okay.

92
00:06:29,120 --> 00:06:29,680
‫Welcome back.

93
00:06:29,690 --> 00:06:35,660
‫So let's go to our enemy A.I. and add in at the end of the investigate behavior.

94
00:06:35,660 --> 00:06:39,440
‫We're going to add in our clear blackboard value.

95
00:06:39,440 --> 00:06:41,450
‫You can see it's got the nice name there.

96
00:06:41,450 --> 00:06:45,620
‫And you can also see that if you go over to the details pane, you can select a blackboard key.

97
00:06:45,620 --> 00:06:47,990
‫We're going to select the last known player location.

98
00:06:47,990 --> 00:06:53,240
‫Even though that doesn't do anything yet, you can see that we have that functionality because we inherited

99
00:06:53,240 --> 00:06:58,260
‫from Blackboard Base and let's just check that it completes automatically.

100
00:06:58,260 --> 00:07:00,830
‫It should do and then it should move on.

101
00:07:00,830 --> 00:07:07,070
‫Let's move it on to a weight task afterwards so that we can see that just goes straight through or completes

102
00:07:07,070 --> 00:07:08,000
‫automatically.

103
00:07:08,090 --> 00:07:17,480
‫So I'm going to play I am going to go and hide myself around a corner as much as I can, and then I'm

104
00:07:17,480 --> 00:07:23,090
‫going to go and have a look at the investigating it went through and actually he's seen me.

105
00:07:23,090 --> 00:07:25,190
‫So let's go and hide again.

106
00:07:25,220 --> 00:07:27,170
‫Go and hide around the corner if I can.

107
00:07:28,610 --> 00:07:31,060
‫I would go and then I'm going to go to the.

108
00:07:31,070 --> 00:07:31,560
‫There you go.

109
00:07:31,580 --> 00:07:35,690
‫It's gone right through the clear blackboard value, which must mean that it succeeded, because we

110
00:07:35,690 --> 00:07:40,430
‫know that if it was a sequence and it failed, it must have it will have stopped and not gone onto the

111
00:07:40,430 --> 00:07:41,000
‫weight.

112
00:07:41,000 --> 00:07:42,950
‫So that's working correctly.

113
00:07:42,950 --> 00:07:48,530
‫The clear black world value is just returning success straight away and going on to waiting the next

114
00:07:48,530 --> 00:07:51,920
‫lecture, we're going to look at how we can actually add in the functionality.

115
00:07:51,920 --> 00:07:52,760
‫I'll see you there.

