﻿1
00:00:04,320 --> 00:00:05,310
‫Hello and welcome.

2
00:00:05,310 --> 00:00:12,450
‫In this lecture, we are going to be setting a blackboard key from our C++ so that we can set the player's

3
00:00:12,450 --> 00:00:15,150
‫location at Begin Play.

4
00:00:15,150 --> 00:00:17,100
‫Let's dive in and see how that works.

5
00:00:17,960 --> 00:00:18,170
‫Okay.

6
00:00:18,170 --> 00:00:26,180
‫So as I said in the last lecture, we want to be able to set some state from our gameplay in the blackboard

7
00:00:26,180 --> 00:00:28,100
‫for the AI to act upon.

8
00:00:28,340 --> 00:00:36,650
‫So the blackboard looks like this and it currently has this self active key, but it doesn't have any

9
00:00:36,650 --> 00:00:37,430
‫other keys here.

10
00:00:37,430 --> 00:00:40,970
‫We can add keys like clicking on this new key button.

11
00:00:40,970 --> 00:00:42,770
‫You can change the type.

12
00:00:43,250 --> 00:00:48,320
‫There isn't actually a type for actors or anything like that that just goes under the nebulous type

13
00:00:48,320 --> 00:00:50,090
‫of object for everything else.

14
00:00:50,090 --> 00:00:56,270
‫There's balls, classes, enemies, etc. but you can choose what kind of type that you want that object

15
00:00:56,270 --> 00:01:01,310
‫to be by going to your blackboard details, dropping down and choosing what base class you'd like.

16
00:01:01,310 --> 00:01:05,840
‫So for example, it's saying here that the self actor is of actor type.

17
00:01:06,020 --> 00:01:08,300
‫This has just been put in here by default.

18
00:01:08,300 --> 00:01:12,740
‫But what we want to do here is set a new key.

19
00:01:12,920 --> 00:01:19,700
‫And to do that, we need to do find out how we can gain access to this in the C++.

20
00:01:20,090 --> 00:01:29,420
‫So we already have an easy function that allows us to get hold of the blackboard by doing a get blackboard

21
00:01:29,420 --> 00:01:32,810
‫component on the AI controller.

22
00:01:32,810 --> 00:01:41,540
‫So simple as we can just do get blackboard component and let's have a look at that blackboard components

23
00:01:42,230 --> 00:01:45,650
‫dot h and have a look what is available in here.

24
00:01:45,650 --> 00:01:54,260
‫We want to be doing something like set key or set blackboard or in fact, it's as simple as just set

25
00:01:54,260 --> 00:01:55,040
‫value.

26
00:01:55,040 --> 00:02:01,880
‫So here you've got a bunch of different functions on that blackboard component that allow you to set

27
00:02:01,880 --> 00:02:06,860
‫these different values so you can do it by a key name, which is an F name here.

28
00:02:06,910 --> 00:02:13,820
‫Then you can set the value as an object, or you can set the class all of the different types that are

29
00:02:13,820 --> 00:02:14,900
‫available here.

30
00:02:15,140 --> 00:02:16,850
‫So let's give that a go.

31
00:02:16,850 --> 00:02:25,700
‫I'm going to go over to the C++ and try and set our player pawns location as one of the variables.

32
00:02:25,700 --> 00:02:31,250
‫So we're going to do first of all, we need to get hold of the blackboard component.

33
00:02:31,250 --> 00:02:34,940
‫So let's give that a shot, get blackboard components.

34
00:02:34,940 --> 00:02:37,070
‫Then we need to have the right includes.

35
00:02:37,070 --> 00:02:42,290
‫So if I hover over the blackboard component on H, you can see that we need to be including behavior

36
00:02:42,290 --> 00:02:44,060
‫tree forward slash blackboard component.

37
00:02:44,060 --> 00:02:52,910
‫So let's do that hash include then it's going to be the behavior tree forward slash blackboard component

38
00:02:52,910 --> 00:02:53,600
‫H.

39
00:02:53,960 --> 00:02:59,180
‫Now we can use the arrow operator on that type and we should be running.

40
00:02:59,180 --> 00:03:03,260
‫We want to, in this case be setting a vector.

41
00:03:03,260 --> 00:03:04,370
‫We want to set the location.

42
00:03:04,370 --> 00:03:12,950
‫So we're setting a vector and not copy the whole line, but just set the vector and then we want to

43
00:03:12,980 --> 00:03:17,630
‫what's the first parameter is the name that we're trying to set so we can use our text macro for that.

44
00:03:17,720 --> 00:03:23,420
‫And I'm going to call it the player location that's going to give us the location at the start because

45
00:03:23,420 --> 00:03:29,060
‫we're calling it in Begin Play and then we need to actually set the location so we can get that from

46
00:03:29,060 --> 00:03:32,630
‫the line of code, getting our player -- first and foremost.

47
00:03:32,690 --> 00:03:41,840
‫So uncomment that and then we want to do the player pawn arrow and get actor location like so and finish

48
00:03:41,840 --> 00:03:43,040
‫off the line with the semicolon.

49
00:03:43,040 --> 00:03:47,750
‫And it's as simple as that to go ahead and set a blackboard value.

50
00:03:47,750 --> 00:03:52,970
‫So your challenge is going to be to do the other half of this, which is to create a key in the blackboard.

51
00:03:52,970 --> 00:03:57,140
‫So add the key to the blackboard, make sure it's of the right type, the right name, and then if everything

52
00:03:57,140 --> 00:04:00,140
‫worked correctly, you should be able to check that value at runtime.

53
00:04:00,140 --> 00:04:01,340
‫Remember last lecture?

54
00:04:01,340 --> 00:04:04,040
‫We saw how we can see the behavior tree.

55
00:04:04,040 --> 00:04:04,850
‫You can do the same thing.

56
00:04:04,850 --> 00:04:09,860
‫You can inspect the blackboard at runtime when you're playing and you should be able to see what value

57
00:04:09,890 --> 00:04:12,090
‫was set by the C++ code.

58
00:04:12,110 --> 00:04:14,420
‫Pause the video and have a go.

59
00:04:15,220 --> 00:04:15,490
‫Okay.

60
00:04:15,490 --> 00:04:16,290
‫Welcome back.

61
00:04:16,300 --> 00:04:21,370
‫So I'm going to go over in to the editor hit compile because I haven't done that already.

62
00:04:21,370 --> 00:04:23,710
‫And we're going to add a new blackboard key.

63
00:04:23,710 --> 00:04:28,600
‫And in this case, we have to get the names right and the types right, otherwise things will go wrong.

64
00:04:28,600 --> 00:04:34,150
‫So we've got a vector key which we're going to be calling our player location, and I'm going to copy

65
00:04:34,150 --> 00:04:38,740
‫that to make sure that we have got the right spelling here.

66
00:04:38,740 --> 00:04:41,170
‫Yes, we have cool beans.

67
00:04:41,560 --> 00:04:48,010
‫And then what we're going to do is we're going to head over and just check that the blackboard details

68
00:04:48,010 --> 00:04:48,940
‫are okay.

69
00:04:48,940 --> 00:04:51,550
‫So yeah, there's a name you could add a description if you wanted.

70
00:04:51,550 --> 00:04:52,570
‫The type is a vector.

71
00:04:52,570 --> 00:04:53,340
‫That's cool.

72
00:04:53,340 --> 00:04:55,170
‫For instance, select.

73
00:04:55,180 --> 00:05:00,190
‫This is a variable that we're not particularly interested in at the moment.

74
00:05:00,190 --> 00:05:00,700
‫Cool.

75
00:05:00,700 --> 00:05:06,160
‫We've got our code has compiled, so let's go and hit play and see whether we can inspect that blackboard

76
00:05:06,160 --> 00:05:06,520
‫value.

77
00:05:06,520 --> 00:05:11,770
‫Go over to the blackboard and you can see we can still have that dropdown of choosing which I, we want

78
00:05:11,770 --> 00:05:12,370
‫this to relate to.

79
00:05:12,370 --> 00:05:17,230
‫We've only got one in our world, but you can see that self actor hasn't been set, but the player's

80
00:05:17,230 --> 00:05:19,270
‫location has indeed been set.

81
00:05:19,270 --> 00:05:21,520
‫Let's check if that is roughly correct.

82
00:05:21,520 --> 00:05:27,730
‫If I f h d possess, have a look at my player and have a look at the player's location.

83
00:05:27,730 --> 00:05:28,420
‫You can see that.

84
00:05:28,420 --> 00:05:30,010
‫Yes, it's pretty much correct.

85
00:05:30,010 --> 00:05:33,220
‫2000 -5100.

86
00:05:33,790 --> 00:05:36,400
‫2000 -5100.

87
00:05:36,400 --> 00:05:39,970
‫So that's setting the value through from C++.

88
00:05:39,970 --> 00:05:40,840
‫Simple as that.

89
00:05:40,990 --> 00:05:44,680
‫We can start to see how we can interface with our behavior trees.

90
00:05:44,680 --> 00:05:50,140
‫In the next lecture, we're going to look at the actual structure of behavior trees and making them

91
00:05:50,170 --> 00:05:51,130
‫do something.

92
00:05:51,130 --> 00:05:52,150
‫The exciting part.

93
00:05:52,180 --> 00:05:52,930
‫See you there.

