﻿1
00:00:04,610 --> 00:00:05,660
‫Hello and welcome.

2
00:00:05,660 --> 00:00:12,290
‫In this lecture, we're going to be creating a new component in C++, this trigger box, which will

3
00:00:12,290 --> 00:00:16,880
‫report to us when we step inside the alcove or we place any object in the alcove.

4
00:00:16,880 --> 00:00:20,930
‫You can see we're getting a little blueprint message up in the top left hand corner.

5
00:00:21,110 --> 00:00:27,350
‫And to do that, we're going to have to understand how overlaps and blocking and different collision

6
00:00:27,350 --> 00:00:29,930
‫responses behave in Unreal.

7
00:00:29,930 --> 00:00:31,730
‫Let's dive in and find out.

8
00:00:32,510 --> 00:00:36,510
‫Now we've already become familiar with how trace channels work.

9
00:00:36,530 --> 00:00:42,650
‫We know that you can have trace responses on the different objects in our scene, such as this shrub.

10
00:00:42,650 --> 00:00:51,620
‫Here, you can see that it has a ignore response to weapon traces, but it does block visibility traces.

11
00:00:52,370 --> 00:00:54,890
‫Then there's this bulletproof glass example.

12
00:00:54,890 --> 00:01:00,250
‫It blocks weapons but allows visibility through and a brick wall which blocks both.

13
00:01:00,260 --> 00:01:03,790
‫So you can see how this system works with trace channels.

14
00:01:03,800 --> 00:01:10,100
‫Now, what happens if we're trying to decide which objects can overlap with each other, which ones

15
00:01:10,100 --> 00:01:12,230
‫pass through, which ones block each other?

16
00:01:12,230 --> 00:01:14,600
‫That can get a little bit more complicated.

17
00:01:14,630 --> 00:01:21,600
‫We saw this already when we tried to get the gargoyle to overlap with our pawn.

18
00:01:21,620 --> 00:01:23,540
‫Now this is how it works.

19
00:01:23,540 --> 00:01:25,940
‫Essentially, we use these object types.

20
00:01:26,480 --> 00:01:31,190
‫Each object can belong to can be a particular object type.

21
00:01:31,190 --> 00:01:34,390
‫And this is different to the kind of type system in C++.

22
00:01:34,400 --> 00:01:36,740
‫These are collision types.

23
00:01:36,740 --> 00:01:43,640
‫So you might have object A and object B and in their settings, if we go and have a look at the settings

24
00:01:43,640 --> 00:01:48,820
‫on our gargoyle, for example, you can see that they have their own object type.

25
00:01:48,830 --> 00:01:55,190
‫This one is a world static object, but then further down they have their responses to other types of

26
00:01:55,190 --> 00:01:56,300
‫objects as well.

27
00:01:56,300 --> 00:02:02,930
‫So you can see that this object will block other world statics, it will block other world dynamics,

28
00:02:02,930 --> 00:02:09,530
‫it will overlap the pawn types, it will block physics bodies and pretty much block every other type.

29
00:02:10,040 --> 00:02:16,310
‫And obviously the pawn itself if we go and find our BP player.

30
00:02:17,040 --> 00:02:23,790
‫And look in its capsule component, look at the details and scroll on down to where it's got a collision

31
00:02:23,790 --> 00:02:24,300
‫preset.

32
00:02:24,300 --> 00:02:29,980
‫If we can expand out the Pawn Collision preset, we can't edit it, but we can see what it's doing.

33
00:02:30,000 --> 00:02:34,440
‫And you can see that it has its own response to world static.

34
00:02:34,440 --> 00:02:38,250
‫So its response to the world static would be to block it.

35
00:02:38,250 --> 00:02:41,070
‫So we've actually got two different options here.

36
00:02:41,070 --> 00:02:49,320
‫The pawn is saying I block world statics, but the gargoyle is saying I overlap pawns.

37
00:02:49,320 --> 00:02:50,670
‫So what should happen?

38
00:02:50,670 --> 00:02:54,960
‫Well, this is where this table comes in and I've got a link to this blog post if you want to read it

39
00:02:54,960 --> 00:02:57,780
‫in full in the lecture resources.

40
00:02:57,780 --> 00:03:02,100
‫So you can see that it takes the least blocking interaction between the two.

41
00:03:02,100 --> 00:03:08,940
‫So if the object A was the pawn and we're saying, hey, I should block that gargoyle, but the gargoyles

42
00:03:08,940 --> 00:03:11,790
‫object B and it's saying, hey, I should overlap that pawn.

43
00:03:11,790 --> 00:03:15,960
‫So it's going to take the least blocking of those two and it's going to overlap.

44
00:03:16,230 --> 00:03:22,020
‫So it does mean that if you want two things to block each other, they both need to agree that that's

45
00:03:22,020 --> 00:03:23,280
‫what they want to do.

46
00:03:23,280 --> 00:03:25,410
‫So let's look at another example here.

47
00:03:25,410 --> 00:03:31,410
‫We've got the player which is of object type pawn, and it's object response to other pawns is to block

48
00:03:31,410 --> 00:03:34,800
‫them and world static objects is to block them.

49
00:03:34,980 --> 00:03:37,800
‫The brick wall is a world static object.

50
00:03:37,800 --> 00:03:40,350
‫It can block pawns and block world static.

51
00:03:40,350 --> 00:03:42,350
‫So these two would agree with each other.

52
00:03:42,360 --> 00:03:46,220
‫Now the shrub is also world static, but it overlaps pawns.

53
00:03:46,230 --> 00:03:50,310
‫It's very much like our gargoyle, but it blocks world statics.

54
00:03:50,310 --> 00:03:56,760
‫So if you go down and have a look at what would happen is the pawn would try and travel through the

55
00:03:56,760 --> 00:04:02,310
‫bush and it could because it takes the least blocking option, which is overlap and it generates an

56
00:04:02,310 --> 00:04:08,430
‫overlap event which we can hook into in code or blueprint, whereas it won't be able to pass through

57
00:04:08,430 --> 00:04:13,860
‫the brick wall and it generates a hit event again, something that we can hook onto in Blueprint or

58
00:04:13,860 --> 00:04:14,910
‫C++.

59
00:04:14,910 --> 00:04:17,820
‫So why do I go into all of this depth?

60
00:04:17,820 --> 00:04:25,830
‫Because what I want to do is put an object that we is basically invisible inside this wall that allows

61
00:04:25,830 --> 00:04:30,630
‫us to put the gargoyle in here and we get an event when that happens.

62
00:04:30,630 --> 00:04:36,390
‫So the gargoyle will prop up an event and say, Hey, I've got something overlapping with me.

63
00:04:36,390 --> 00:04:37,860
‫So why is all of this important?

64
00:04:37,860 --> 00:04:44,700
‫Because I want to put an object that's invisible but will overlap with the gargoyle and let us know

65
00:04:44,700 --> 00:04:45,540
‫about that fact.

66
00:04:45,540 --> 00:04:50,460
‫We can then query it from C++ or we can get events in Blueprint either way.

67
00:04:50,460 --> 00:04:55,920
‫And the way we're going to do this is, first of all, create a blueprint from this dungeon wall.

68
00:04:55,920 --> 00:05:01,290
‫So I'm going to click the blueprint button in the details pane, create a new subclass, and I'm going

69
00:05:01,290 --> 00:05:11,970
‫to name it beep, underscore secret wall and we're going to hit select to create it and a docket to

70
00:05:11,970 --> 00:05:15,300
‫our main window and it's got a mover on it.

71
00:05:15,300 --> 00:05:23,070
‫What I also want to add in here is essentially a component which is called a box collision.

72
00:05:23,340 --> 00:05:27,930
‫So if we click on a box collision, you can see it's completely invisible.

73
00:05:27,930 --> 00:05:35,100
‫It just gives you some box extents which we can change, we can make them larger so that anywhere we

74
00:05:35,100 --> 00:05:39,600
‫place the gargoyle in this box, it's going to accept it.

75
00:05:40,230 --> 00:05:44,880
‫And we can see that it has got collision options down here.

76
00:05:44,880 --> 00:05:49,200
‫We've got an overlap all dynamic as the default, but as the default preset.

77
00:05:49,200 --> 00:05:54,810
‫But if we hit custom, you can see we can change the object types and we can change how it responds

78
00:05:54,810 --> 00:05:56,520
‫to different things in here.

79
00:05:56,520 --> 00:06:04,170
‫And I think most importantly, as you can see, it's set up to overlap with most object types, which

80
00:06:04,170 --> 00:06:09,840
‫means that even if they're not set to overlap with world dynamic, it's going to overlap.

81
00:06:09,840 --> 00:06:11,130
‫It's not going to block anything.

82
00:06:11,130 --> 00:06:14,250
‫It's going to let us position the gargoyle in here.

83
00:06:14,250 --> 00:06:19,530
‫So I'm going to go and delete that component from the scene, because what I want to do is create a

84
00:06:19,530 --> 00:06:24,780
‫new component in C++ based off of that box collision.

85
00:06:24,780 --> 00:06:31,080
‫Now I just want to show you that with this box, if we set it back to the default preset it was on,

86
00:06:31,080 --> 00:06:39,000
‫which was overlap all dynamic I believe and we check or as is already checked actually generate overlap

87
00:06:39,000 --> 00:06:40,470
‫events is already checked.

88
00:06:40,470 --> 00:06:48,840
‫Then we can go over into our event graph and we can right click in here and look for overlap.

89
00:06:48,840 --> 00:06:56,400
‫And right at the top you can see an add on component begin overlap for the box.

90
00:06:56,400 --> 00:07:05,760
‫So if we click that and actually let's rename the box component to trigger area like.

91
00:07:05,760 --> 00:07:13,410
‫So then basically if we overlap with the trigger area, we're going to get a list of properties of the

92
00:07:13,410 --> 00:07:16,410
‫thing that's overlapping with us so we could take the.

93
00:07:16,850 --> 00:07:17,450
‫It's overlapping.

94
00:07:17,450 --> 00:07:19,700
‫We could get its name.

95
00:07:19,700 --> 00:07:22,850
‫So get display name is the name of the node.

96
00:07:22,850 --> 00:07:30,350
‫And then we could take that and print the result string and hook that up to the execution pin and we

97
00:07:30,350 --> 00:07:32,570
‫can go ahead and hit play.

98
00:07:32,570 --> 00:07:40,100
‫And if we walk up to the area, you can see that it's saying the beep player is the thing overlapping

99
00:07:40,100 --> 00:07:40,190
‫it.

100
00:07:40,190 --> 00:07:42,080
‫Now I can't see that area because it's so dark.

101
00:07:42,080 --> 00:07:50,930
‫So I'm just going to go to the secret wall again, a beep and I'm going to add in a spot light component,

102
00:07:51,290 --> 00:07:57,710
‫which I'm going to place in this little alcove, rotating it to face down and illuminating the space

103
00:07:57,710 --> 00:07:59,660
‫where we want the object.

104
00:07:59,690 --> 00:08:01,940
‫Now in the scene, we can see it very clearly.

105
00:08:01,940 --> 00:08:06,560
‫So let's go ahead and hit play and we can walk up to that alcove.

106
00:08:06,560 --> 00:08:14,300
‫If we overlap it, it says there's the beep player overlapping and we can go and grab our gargoyle from

107
00:08:14,300 --> 00:08:24,020
‫this cell using our newly minted grabber, and we can take that gargoyle and place it in this area.

108
00:08:24,230 --> 00:08:33,650
‫However, it doesn't seem to be generating any overlap events, and that's because just like we need,

109
00:08:33,650 --> 00:08:35,510
‫there's two parties to the collision.

110
00:08:35,510 --> 00:08:38,510
‫There's also two parties to generating overlap events.

111
00:08:38,510 --> 00:08:45,680
‫So just because we have it enabled on that box component doesn't mean that the gargoyle moving into

112
00:08:45,680 --> 00:08:48,830
‫it is actually going to alert us to any overlap events.

113
00:08:48,830 --> 00:08:55,220
‫So what we have to do is we have to go to the gargoyle and check it, generate overlap events as well.

114
00:08:55,310 --> 00:08:58,520
‫So then the overlap events should happen.

115
00:08:58,520 --> 00:09:06,530
‫Let's go and pick up the gargoyle, take him over to the alcove and stick him in.

116
00:09:06,530 --> 00:09:09,440
‫And now we are getting an event coming up.

117
00:09:09,440 --> 00:09:14,330
‫When that happens, the Gargoyle statue is indeed being registered.

118
00:09:14,330 --> 00:09:19,340
‫Now, I don't want to be using blueprint events in this particular case.

119
00:09:19,340 --> 00:09:26,990
‫So what I want to do is take our trigger area component and actually turn that into some a C++ component

120
00:09:26,990 --> 00:09:32,840
‫that can evaluate whether it's got the Gargoyle statue at once or not already in it.

121
00:09:33,200 --> 00:09:38,150
‫The way we're going to do this is we're going to go to the add components, create a new C++ component.

122
00:09:38,150 --> 00:09:44,540
‫And as the parent class, instead of choosing active component or scene component, we're going to go

123
00:09:44,540 --> 00:09:50,990
‫to all classes and we're going to search for the box component instead.

124
00:09:50,990 --> 00:09:55,400
‫And you can see the shape components, box components, the one we want and we can go ahead and hit

125
00:09:55,400 --> 00:09:56,090
‫next.

126
00:09:56,090 --> 00:10:00,380
‫So I'd like to challenge you to create this component now that I've shown you how to set the parent

127
00:10:00,380 --> 00:10:01,040
‫class.

128
00:10:01,040 --> 00:10:07,040
‫So you're going to name it trigger components and you're going to have to copy some things from the

129
00:10:07,040 --> 00:10:10,220
‫other components we've created because it's not set up in the same way.

130
00:10:10,220 --> 00:10:15,230
‫Seeing as we're deriving from a different parent, you're going to have to copy the you class line.

131
00:10:15,230 --> 00:10:20,600
‫That whole line is basically empty on the trigger component as you will create it.

132
00:10:20,600 --> 00:10:28,610
‫So copy that from either your grabber or your mover, and otherwise you won't be able to add your components

133
00:10:28,610 --> 00:10:30,170
‫in to your blueprints.

134
00:10:30,170 --> 00:10:39,500
‫So then you should use this new trigger components to replace our current box component and print something

135
00:10:39,500 --> 00:10:40,280
‫from Begin Play.

136
00:10:40,280 --> 00:10:45,650
‫Again, it big in play won't be set up automatically for you, so you're going to have to copy from

137
00:10:45,650 --> 00:10:50,410
‫the header file and C++ file of our other components in order to set it up.

138
00:10:50,420 --> 00:10:52,400
‫Pause the video and have a go.

139
00:10:55,580 --> 00:10:56,060
‫Okay.

140
00:10:56,060 --> 00:10:57,050
‫Welcome back.

141
00:10:57,050 --> 00:10:59,930
‫So I'm going to call it the trigger component.

142
00:10:59,930 --> 00:11:02,300
‫All one word and hit to create class.

143
00:11:02,300 --> 00:11:10,940
‫So as predicted you class line is got nothing inside the parentheses and if we go and have a look at

144
00:11:11,540 --> 00:11:17,420
‫our editor and go to the BP secret wall, try to add this component and search for trigger, you can

145
00:11:17,420 --> 00:11:19,340
‫see nothing comes up.

146
00:11:19,340 --> 00:11:25,370
‫And the reason for this is if we went over to our grab a dot H and had a look at its use class line,

147
00:11:25,550 --> 00:11:30,350
‫you can see that there's a bit in here that says blueprint spawn able component.

148
00:11:30,350 --> 00:11:33,140
‫So crucially, we need to copy this.

149
00:11:33,140 --> 00:11:34,340
‫It also has a class group.

150
00:11:34,340 --> 00:11:40,670
‫We might as well copy the whole thing because this allows us to create this component in blueprint so

151
00:11:40,670 --> 00:11:45,500
‫we can go and paste this as the class line for the trigger component.

152
00:11:45,920 --> 00:11:50,660
‫And then the other thing, if we go to grab, you can see it's got big in play, it's within a protected

153
00:11:50,660 --> 00:11:57,470
‫section and we can just copy the definition of that begin play function, copy it over into our trigger

154
00:11:57,470 --> 00:12:03,590
‫component and put it as it was in the grabber, just underneath the generated body.

155
00:12:03,650 --> 00:12:08,480
‫Then we can go into our grab a CP and see how big in play was defined.

156
00:12:08,480 --> 00:12:12,650
‫In here you can see that it has this cool to super big in play that is actually important.

157
00:12:12,650 --> 00:12:15,920
‫So we're going to copy that, go over into a trigger component.

158
00:12:15,920 --> 00:12:26,180
‫CP And we're going to change the you grab a colon colon to you trigger component, begin play.

159
00:12:26,810 --> 00:12:34,220
‫And then in here we can put in our you log and we're just going to write a simple message such as trigger

160
00:12:34,220 --> 00:12:38,120
‫component alive and we'll go ahead and compile.

161
00:12:38,120 --> 00:12:42,890
‫This may take a little while, seeing as we've made some fairly significant changes to our header file.

162
00:12:42,890 --> 00:12:49,070
‫And once that's done, we can go into our BP secret wall, go to add and search for trigger.

163
00:12:49,310 --> 00:12:52,070
‫And in here you can see we've got that trigger component.

164
00:12:52,070 --> 00:12:53,690
‫We can now add that in.

165
00:12:53,690 --> 00:12:59,000
‫We can remove our trigger area that we've set up previously.

166
00:12:59,120 --> 00:13:03,770
‫Just go ahead and delete that and check yet we want to delete it.

167
00:13:03,770 --> 00:13:09,200
‫It's going to basically invalidate this event that we created and we can check that the collisions are

168
00:13:09,200 --> 00:13:11,930
‫set up as we want on the trigger if we're going to have a look.

169
00:13:11,930 --> 00:13:15,860
‫Yet, it's set to overlap all dynamic and to generate overlap events.

170
00:13:15,860 --> 00:13:21,890
‫And finally, what we need to replace is this event here where we're going to select our trigger right

171
00:13:21,890 --> 00:13:31,370
‫click and go to unfurl the add event for trigger collision and add on on component begin overlap.

172
00:13:31,370 --> 00:13:33,050
‫That's what we were using before.

173
00:13:33,170 --> 00:13:41,360
‫Hook up the active pin and hook up the execution pin to head over to the dungeon level.

174
00:13:41,690 --> 00:13:48,080
‫Go and pick up the gargoyle, try and stick it in the alcove and we notice that's not working.

175
00:13:48,080 --> 00:13:50,330
‫So now we've got that trigger set up.

176
00:13:50,330 --> 00:13:56,150
‫Let's go to the viewport and you can see that actually the trigger isn't been it hasn't been made big

177
00:13:56,150 --> 00:13:56,360
‫enough.

178
00:13:56,360 --> 00:13:57,680
‫We haven't positioned it correctly.

179
00:13:57,680 --> 00:14:06,590
‫So let's go and position it in the center of the alcove and let's increase the box extent properties

180
00:14:06,590 --> 00:14:11,810
‫so that we catch whatever we've put inside this alcove area.

181
00:14:12,480 --> 00:14:17,810
‫Doesn't matter if it is a little bit bigger and gives us a safety margin and we can go into the dungeon,

182
00:14:17,810 --> 00:14:20,180
‫hit play and then step into the alcove.

183
00:14:20,180 --> 00:14:25,340
‫And sure enough, it detects that the BP player has walked in to that alcove.

184
00:14:25,370 --> 00:14:25,940
‫Great stuff.

185
00:14:25,940 --> 00:14:31,400
‫In this lecture, we've learned all about object types and object type responses, and we've used that

186
00:14:31,400 --> 00:14:34,100
‫to set up this trigger component.

187
00:14:34,100 --> 00:14:35,930
‫I'll see you in the next lecture.

