﻿1
00:00:04,350 --> 00:00:05,340
‫Hello and welcome.

2
00:00:05,340 --> 00:00:12,540
‫In this lecture, we are going to be accessing the overlapping actors in something called an array so

3
00:00:12,540 --> 00:00:19,860
‫that we can be printing out the actors that we see inside this volume entirely from C++.

4
00:00:19,860 --> 00:00:21,510
‫Let's dive in and see how it's done.

5
00:00:22,420 --> 00:00:30,970
‫So as in previous analogies, let's imagine that a type or a variable is a box in which we put a value.

6
00:00:31,000 --> 00:00:35,290
‫Now, what happens if we don't know how many values we want to store?

7
00:00:35,290 --> 00:00:36,670
‫We might create lots of variables.

8
00:00:36,670 --> 00:00:39,610
‫If we knew that we were going to have five, we might make five variables.

9
00:00:39,610 --> 00:00:45,910
‫But what if we had something that is unpredictably many, such as the number of actors we have in our

10
00:00:46,540 --> 00:00:51,220
‫level, or the actors that are overlapping with a particular trigger volume?

11
00:00:51,370 --> 00:01:00,220
‫In this case, we need to use a new data type called a T array in Unreal and basically a T array of

12
00:01:00,220 --> 00:01:01,270
‫a certain type.

13
00:01:01,270 --> 00:01:08,860
‫Here again, we're seeing these angle brackets that are, as we said, previously, compile time parameters.

14
00:01:08,860 --> 00:01:14,800
‫And this time we're taking in, again, a type that is telling us what type we can store in our array.

15
00:01:14,800 --> 00:01:21,520
‫An array is like a variable, except that it has multiple boxes and the number of boxes that we have

16
00:01:21,550 --> 00:01:23,980
‫can be different when we're playing our game.

17
00:01:23,980 --> 00:01:24,940
‫It can change.

18
00:01:24,940 --> 00:01:28,330
‫We can add more or less as we go through the game.

19
00:01:28,330 --> 00:01:32,650
‫As things start to overlap, we'd add more boxes as things that leave the overlapping zone.

20
00:01:32,650 --> 00:01:33,850
‫We'd take them away.

21
00:01:33,850 --> 00:01:37,510
‫And as I said, this is a parameter within these.

22
00:01:38,300 --> 00:01:39,560
‫Angle brackets.

23
00:01:39,560 --> 00:01:46,190
‫And so we could have a tray of ints, for example, which would store different integers in those boxes.

24
00:01:46,190 --> 00:01:52,940
‫We could have a tray of actor pointers, and this would actually store the pointers in the boxes, which

25
00:01:52,940 --> 00:01:55,880
‫would point to actors out in the world.

26
00:01:55,880 --> 00:01:57,740
‫And as you can see, they could even overlap.

27
00:01:57,740 --> 00:02:01,430
‫So some of these pointers point to the same actors.

28
00:02:01,460 --> 00:02:04,760
‫Now, in practice, that wouldn't be very useful, but it's certainly possible.

29
00:02:04,760 --> 00:02:11,450
‫So I want to revisit the documentation of the primitive component, because what I'm looking for here

30
00:02:11,450 --> 00:02:16,490
‫is a function called get overlapping actors.

31
00:02:16,490 --> 00:02:21,170
‫And if you have a look at the get overlapping actors function, there's a couple of versions of it.

32
00:02:21,530 --> 00:02:26,810
‫But the one that's most interesting to me is the second one.

33
00:02:27,170 --> 00:02:30,470
‫It doesn't have a return value, it's a void return value.

34
00:02:30,470 --> 00:02:38,750
‫But you can see that the first parameter here is a t array of actor pointers with an ampersand at the

35
00:02:38,750 --> 00:02:43,700
‫end, meaning that this whole thing is a reference to a t array.

36
00:02:43,700 --> 00:02:51,950
‫Now notice it's not a constant reference, so we can assume that this parameter is actually an out parameter.

37
00:02:51,950 --> 00:03:00,230
‫It gives us the result of the overlapping actors and it tells us which actors are currently overlapping

38
00:03:00,230 --> 00:03:02,450
‫with our primitive component.

39
00:03:02,450 --> 00:03:06,740
‫Now it just so happens that our box component is a primitive component.

40
00:03:06,740 --> 00:03:09,890
‫So our trigger component is also a primitive component.

41
00:03:09,890 --> 00:03:12,680
‫And who would have access to this function?

42
00:03:13,460 --> 00:03:18,200
‫There's a second argument here, but we don't need to worry about that because it's actually got a default

43
00:03:18,200 --> 00:03:19,670
‫value if we use it.

44
00:03:19,670 --> 00:03:26,120
‫So let's go ahead and try and get hold of and populate a tray of actor pointers.

45
00:03:26,120 --> 00:03:27,710
‫We're going to go into the trigger component.

46
00:03:27,710 --> 00:03:31,610
‫CP We're going to go down to the tick component.

47
00:03:31,700 --> 00:03:38,270
‫And in here we're going to create an empty t array that we can populate using this function.

48
00:03:38,270 --> 00:03:48,170
‫So it's the syntax is t array open angle brackets a actor star to say that we're having a t array of

49
00:03:48,170 --> 00:03:55,310
‫actor pointers, close the angle brackets and then we can give this variable name as actors.

50
00:03:55,310 --> 00:04:05,780
‫Then we would call to get overlapping actors and we would pass in the actors array.

51
00:04:06,590 --> 00:04:06,950
‫Now.

52
00:04:06,950 --> 00:04:11,900
‫I don't know why they don't just pass this out as a return value, but.

53
00:04:12,840 --> 00:04:13,450
‫There you go.

54
00:04:13,470 --> 00:04:18,340
‫It gives us an opportunity to use those parameters a little bit more.

55
00:04:18,360 --> 00:04:19,530
‫Now, that's all well and good.

56
00:04:19,530 --> 00:04:22,350
‫We've got some actors in an array.

57
00:04:22,710 --> 00:04:24,120
‫There's a variable length of them.

58
00:04:24,120 --> 00:04:25,140
‫There might be quite a few.

59
00:04:25,140 --> 00:04:26,520
‫There might be zero.

60
00:04:26,730 --> 00:04:29,670
‫What do we do with arrays like this?

61
00:04:29,670 --> 00:04:34,020
‫Well, we can query how many items are in the array.

62
00:04:34,020 --> 00:04:41,040
‫You can use array, dot num parentheses and that can return an integer telling you how many items are

63
00:04:41,040 --> 00:04:41,610
‫in the array.

64
00:04:41,610 --> 00:04:48,630
‫So in this particular array we could say that there are five and then we can access the items inside

65
00:04:48,630 --> 00:04:52,020
‫that array by using these square brackets.

66
00:04:52,410 --> 00:04:56,100
‫And then the number that you pass into the square brackets tells you which item to get.

67
00:04:56,100 --> 00:05:02,820
‫And it's a usual convention in a lot of programming languages that we start counting from zero in arrays.

68
00:05:02,820 --> 00:05:09,630
‫So the zeroth element of an array is the first one, the one element of an array is the second, etc.

69
00:05:09,630 --> 00:05:15,180
‫And so you end up with the last element always being one less than the number of elements in the array.

70
00:05:15,660 --> 00:05:17,640
‫So how can we use this knowledge?

71
00:05:17,640 --> 00:05:24,540
‫Well, for example, we could only print the overlapping actors if there is more than one of them.

72
00:05:24,540 --> 00:05:26,070
‫So how would we do this?

73
00:05:26,070 --> 00:05:38,130
‫We would put an if statement saying that if the actor's dot num parentheses is greater than zero, then

74
00:05:38,130 --> 00:05:46,500
‫we can do something in here, such as get access to our actors zero element because we know that if

75
00:05:46,500 --> 00:05:50,130
‫it's greater than zero, there must be at least one element in there.

76
00:05:50,130 --> 00:05:54,690
‫So the zeroth element of this array must have something in.

77
00:05:54,690 --> 00:05:59,940
‫We couldn't guarantee that the first element, the one element of the array has got anything in or the

78
00:05:59,940 --> 00:06:01,620
‫two element has anything in.

79
00:06:01,620 --> 00:06:06,870
‫We would have to check whether we have enough items in the array in order to do that, but we definitely

80
00:06:06,870 --> 00:06:08,700
‫know that there is the first one here.

81
00:06:08,700 --> 00:06:12,690
‫So let's challenge you to print the first overlapping actor from that array.

82
00:06:12,720 --> 00:06:16,680
‫Use the array to get the pointer using those square brackets.

83
00:06:16,680 --> 00:06:22,290
‫Then you're going to use that pointer to call, get actor, name or label, and then you're going to

84
00:06:22,290 --> 00:06:25,140
‫print that out, pause the video and have a go.

85
00:06:28,340 --> 00:06:29,650
‫Hey, welcome back.

86
00:06:29,660 --> 00:06:34,730
‫So we can get we have got hold of the pointer here using this square brackets.

87
00:06:34,730 --> 00:06:41,300
‫And I'm then going to get hold of the name straight way by using the arrow operator and calling get

88
00:06:41,300 --> 00:06:43,610
‫actor, name or label.

89
00:06:44,090 --> 00:06:50,210
‫And I'm going to put that in an F string variable called actor name.

90
00:06:50,210 --> 00:06:56,510
‫Then we're going to do a U log, which we're going to call the overlapping colon.

91
00:06:56,510 --> 00:06:58,390
‫And then percent s.

92
00:06:58,400 --> 00:07:03,740
‫And then the second argument here should be asterisk, actor name.

93
00:07:03,740 --> 00:07:09,650
‫Then we can recompile, hop into our output log docket in the layout.

94
00:07:09,650 --> 00:07:16,130
‫Then we're going to open up the BPP secret wall because I don't want to be printing this string that

95
00:07:16,130 --> 00:07:17,270
‫confuses things.

96
00:07:17,270 --> 00:07:24,230
‫In Blueprint, we're doing this now from C++, so let's go over in to the dungeon level hit play.

97
00:07:25,160 --> 00:07:28,700
‫And obviously nothing is overlapping that actor right now.

98
00:07:28,700 --> 00:07:31,850
‫So what happens if we go and step inside?

99
00:07:31,940 --> 00:07:36,320
‫You can see that it instantly starts printing, that we're overlapping the beep player.

100
00:07:36,560 --> 00:07:37,760
‫Fantastic stuff.

101
00:07:37,760 --> 00:07:40,370
‫What if we were to go and get the gargoyle instead?

102
00:07:40,370 --> 00:07:43,820
‫Take it over to the alcove, stick it in and there you go.

103
00:07:43,820 --> 00:07:46,400
‫It says it's overlapping the gargoyle statue.

104
00:07:46,670 --> 00:07:47,270
‫Great stuff.

105
00:07:47,270 --> 00:07:55,340
‫So we have learned how to use a t array to get a list of actors and to find out how many things are

106
00:07:55,340 --> 00:08:00,980
‫in that list and how to get hold of a particular item from that list.

107
00:08:00,980 --> 00:08:05,750
‫In the next lecture, we're going to be looking at some programming structures that allow us to deal

108
00:08:05,750 --> 00:08:10,790
‫with variable numbers of things to do a variable number of tasks.

109
00:08:10,790 --> 00:08:11,870
‫I'll see you there.

