﻿1
00:00:04,130 --> 00:00:04,610
‫Hey.

2
00:00:04,610 --> 00:00:05,450
‫Welcome back.

3
00:00:05,480 --> 00:00:09,080
‫Now, we've already created a base -- C++ class.

4
00:00:09,200 --> 00:00:16,310
‫In this video, we're going to derive from that class to create a new child class based on base --.

5
00:00:16,340 --> 00:00:19,310
‫So let's discuss why we'd want to do such a thing.

6
00:00:19,580 --> 00:00:26,300
‫So we have this base -- class and we know that we're going to have two different classes that derive

7
00:00:26,300 --> 00:00:27,080
‫from base --.

8
00:00:27,080 --> 00:00:30,020
‫We're going to have our tank and we're going to have the tower.

9
00:00:30,050 --> 00:00:34,760
‫Now, the base -- contains meshes, a capsule as well as a spawn point.

10
00:00:34,760 --> 00:00:38,210
‫And these are things that the Tank and tower can both inherit.

11
00:00:38,360 --> 00:00:44,480
‫But the tank and tower are also going to have some functionality that differs from each other.

12
00:00:44,480 --> 00:00:50,060
‫For one, our tank is going to move around in the world and it's also going to be controlled by the

13
00:00:50,060 --> 00:00:50,720
‫player.

14
00:00:50,720 --> 00:00:55,220
‫So it'll need to be configured to take input from the keyboard and mouse.

15
00:00:55,220 --> 00:00:57,950
‫The tower, on the other hand, is just going to sit there.

16
00:00:57,980 --> 00:01:03,860
‫It has no need for any input from the player as its actions will all be controlled by code.

17
00:01:03,860 --> 00:01:10,010
‫So because the tank and tower will behave differently, we're going to make use of inheritance to create

18
00:01:10,010 --> 00:01:16,730
‫child classes of base -- so we can inherit what they have in common and then add to each class those

19
00:01:16,730 --> 00:01:18,290
‫features that will be different.

20
00:01:18,290 --> 00:01:23,960
‫So we're back here in the editor and I'm going to go into our C++ classes, Tune Tank's folder where

21
00:01:23,960 --> 00:01:29,240
‫we have our base -- class and this will be the class that we're deriving from.

22
00:01:29,240 --> 00:01:35,480
‫Now we can right click here and select create C++ class derived from base --.

23
00:01:35,480 --> 00:01:41,690
‫So let's choose that and I'm going to allow it to stick this class in the same source slash tune tanks

24
00:01:41,690 --> 00:01:43,550
‫folder as base --.

25
00:01:43,610 --> 00:01:47,360
‫And for the name of this, I'm going to call it tank.

26
00:01:47,360 --> 00:01:54,560
‫So our tank class will be the class for our actual tank -- that we're controlling and moving around

27
00:01:54,560 --> 00:01:55,400
‫in the world.

28
00:01:55,430 --> 00:01:57,410
‫So let's click create class.

29
00:01:57,560 --> 00:02:06,470
‫Okay, so we've compiled and vs code has opened up with our new tank file and we also have Tank CP.

30
00:02:06,500 --> 00:02:08,210
‫Now these are pretty bare.

31
00:02:08,210 --> 00:02:14,570
‫There's really nothing here, but even though we can't see them, we have inherited some things from

32
00:02:14,570 --> 00:02:15,950
‫the base -- class.

33
00:02:15,950 --> 00:02:19,580
‫We do have those components that we've added to base --.

34
00:02:19,580 --> 00:02:23,810
‫Even though those are private variables, they still exist in this class.

35
00:02:23,810 --> 00:02:29,030
‫So now that we've created our tank class, let's talk about a couple of things.

36
00:02:29,030 --> 00:02:31,880
‫The tank will need that the turret will not.

37
00:02:31,880 --> 00:02:37,490
‫Well, since we're going to be controlling the tank, we're going to need a way to focus on the tank

38
00:02:37,490 --> 00:02:39,530
‫as it's rolling around throughout the level.

39
00:02:39,950 --> 00:02:43,880
‫Now, in this picture, this here is a camera component.

40
00:02:43,880 --> 00:02:47,030
‫It's C++ class is you camera component.

41
00:02:47,180 --> 00:02:55,100
‫And this red line here is called a spring arm component and its C++ class is you spring arm component.

42
00:02:55,100 --> 00:03:01,370
‫Adding these components to a -- allows us to view the -- from the point of view of the camera.

43
00:03:01,370 --> 00:03:07,790
‫And if the camera and its spring arm are attached to the -- in some way, they will follow the --

44
00:03:07,790 --> 00:03:08,930
‫around in the world.

45
00:03:08,930 --> 00:03:14,540
‫Now, back here in the editor, if we go back to our --'s folder and open BP -- tank, we can click

46
00:03:14,540 --> 00:03:16,730
‫the viewport so we can see everything.

47
00:03:16,730 --> 00:03:22,100
‫And then we can select the capsule comp and click add and select spring arm.

48
00:03:22,100 --> 00:03:24,080
‫This is a spring arm component.

49
00:03:24,080 --> 00:03:25,610
‫It looks like a red line.

50
00:03:25,730 --> 00:03:31,490
‫Now with our spring arm component selected, we can add another component and choose camera.

51
00:03:31,490 --> 00:03:37,400
‫Now, once we've added the camera attached to the spring arm, we now have a way to see from the point

52
00:03:37,400 --> 00:03:41,230
‫of view of the camera once we actually start controlling the --.

53
00:03:41,240 --> 00:03:43,040
‫Now the spring arm is pretty useful.

54
00:03:43,040 --> 00:03:49,250
‫It has this target arm length and if you adjust it, you'll see that the camera adjusts along with the

55
00:03:49,250 --> 00:03:49,940
‫spring arm.

56
00:03:49,940 --> 00:03:54,470
‫So this is a way to control how far away the camera is from the --.

57
00:03:54,470 --> 00:04:00,170
‫So these are definitely things that we want on our -- class, but we're going to add them from the

58
00:04:00,170 --> 00:04:04,460
‫C++ side rather than just adding them here in the blueprint.

59
00:04:04,460 --> 00:04:05,750
‫So I'm going to delete those.

60
00:04:05,750 --> 00:04:10,130
‫So for your challenge, I'd like you to add some things to the tank class.

61
00:04:10,130 --> 00:04:15,890
‫For one, we need a spring arm component and a camera component, so create these variables and make

62
00:04:15,890 --> 00:04:16,790
‫them pointers.

63
00:04:16,790 --> 00:04:21,920
‫Go ahead and make a public and a private section and put these variables in the private section.

64
00:04:21,920 --> 00:04:27,590
‫Now we'll need these to be U properties, so give them you property macros and fill in those macros

65
00:04:27,590 --> 00:04:31,610
‫with the appropriate specifiers based on what you've learned in the previous lectures.

66
00:04:31,640 --> 00:04:36,920
‫Now, once you've created these variables, create a constructor and put this in the public section

67
00:04:36,920 --> 00:04:44,120
‫and define it in the CP file, and then inside the constructor construct our camera and spring arm components

68
00:04:44,120 --> 00:04:46,340
‫using create default sub object.

69
00:04:46,340 --> 00:04:50,750
‫Make sure to use setup attachment to attach these components to something.

70
00:04:50,750 --> 00:04:54,380
‫We'd like our spring arm component attached to the root component.

71
00:04:54,380 --> 00:05:00,500
‫So use root component and set setup attachment and for the camera, attach it to the spring arm.

72
00:05:00,500 --> 00:05:02,870
‫You can refer back to the base -- class.

73
00:05:03,020 --> 00:05:05,950
‫A Remind yourself what the code looks like to do these things.

74
00:05:05,960 --> 00:05:09,710
‫Go ahead and pause the video and add these things to the tank class.

75
00:05:12,580 --> 00:05:13,180
‫All right.

76
00:05:13,180 --> 00:05:14,380
‫So we're here in Tank.

77
00:05:15,250 --> 00:05:16,540
‫Now, first things first.

78
00:05:16,540 --> 00:05:20,110
‫I'd like to have a public section and a private section.

79
00:05:20,350 --> 00:05:24,840
‫So the private section will be where we add these two new components.

80
00:05:24,850 --> 00:05:31,810
‫We're going to want a U spring arm component, which will be a pointer, and we can call this spring

81
00:05:31,810 --> 00:05:32,290
‫arm.

82
00:05:32,290 --> 00:05:37,760
‫And we'll also need a new camera component and we'll call this camera.

83
00:05:37,780 --> 00:05:38,260
‫That's okay.

84
00:05:38,260 --> 00:05:39,970
‫If your names are slightly different.

85
00:05:40,090 --> 00:05:45,070
‫Now, right off the bat, I'm seeing the IntelliSense errors here, which means I'm going to need to

86
00:05:45,070 --> 00:05:46,420
‫forward declare these.

87
00:05:46,420 --> 00:05:51,280
‫So I'm going to use class with spring arm and class with camera.

88
00:05:51,280 --> 00:05:53,150
‫And now these are forward declared.

89
00:05:53,170 --> 00:05:55,240
‫Now we need our new properties.

90
00:05:55,240 --> 00:05:57,460
‫So let's add the new property macros.

91
00:05:57,970 --> 00:06:02,930
‫And inside the property macro we're going to want to have some specifiers.

92
00:06:02,950 --> 00:06:09,550
‫These will be visible anywhere as we saw that the components need to have visible anywhere for us to

93
00:06:09,550 --> 00:06:13,010
‫be able to adjust their parameters in the details panel.

94
00:06:13,030 --> 00:06:18,550
‫Now, I'm not seeing any immediate need for exposure to the event graph, so I don't think we need blueprint

95
00:06:18,550 --> 00:06:20,600
‫read, write or blueprint read only.

96
00:06:20,620 --> 00:06:21,160
‫That's okay.

97
00:06:21,160 --> 00:06:23,770
‫If you added them, I'm going to leave them out now.

98
00:06:23,770 --> 00:06:25,630
‫I'm going to give these a category.

99
00:06:26,410 --> 00:06:32,230
‫And since these are components, I'm going to just stick them in our components category along with

100
00:06:32,230 --> 00:06:33,330
‫our other components.

101
00:06:33,340 --> 00:06:38,470
‫Now I'm not exposing these to the event graph, so I don't need our meta allow private access specified

102
00:06:38,500 --> 00:06:38,940
‫here.

103
00:06:38,950 --> 00:06:45,640
‫So this is enough for spring arm and I'd like to give the camera component the same you property.

104
00:06:46,180 --> 00:06:47,590
‫So I'm copying it over.

105
00:06:47,590 --> 00:06:49,270
‫So now we have our components.

106
00:06:49,420 --> 00:06:54,700
‫The next thing to do is to construct them in the constructor, which means we need a constructor.

107
00:06:54,700 --> 00:07:02,650
‫Now the constructor will be the same name as the class, so it's a tank and we need to define this constructor

108
00:07:02,650 --> 00:07:03,910
‫in the CP file.

109
00:07:03,910 --> 00:07:08,710
‫So let's go to Tank CP and create a tank.

110
00:07:09,520 --> 00:07:16,180
‫So there's our function body and the tank constructor must be prefixed with our class name and the scope

111
00:07:16,180 --> 00:07:17,710
‫resolution operator.

112
00:07:17,710 --> 00:07:19,360
‫That's these double colons here.

113
00:07:19,360 --> 00:07:24,850
‫That way we're not just creating a new function, but defining our constructor for this class.

114
00:07:24,850 --> 00:07:27,130
‫Now we'd like to construct these components.

115
00:07:27,130 --> 00:07:29,530
‫So let's start with the spring arm.

116
00:07:29,860 --> 00:07:39,160
‫So we're going to say spring arm equals create default sub object and this will be a u spring arm component.

117
00:07:41,260 --> 00:07:45,310
‫And for the text, I'll simply call this spring arm.

118
00:07:46,270 --> 00:07:54,490
‫And for the attachment, we're going to set spring arm, set up attachment, passing in root component.

119
00:07:55,920 --> 00:07:56,220
‫Now.

120
00:07:56,220 --> 00:07:57,240
‫I was waiting for it.

121
00:07:57,240 --> 00:07:58,050
‫There it is.

122
00:07:58,050 --> 00:08:03,920
‫The IntelliSense error saying pointer to incomplete class type use spring arm component.

123
00:08:03,930 --> 00:08:10,320
‫That's because we need to include the header file since we're creating and using a spring arm component.

124
00:08:10,320 --> 00:08:16,020
‫So here's my unreal engine documentation and if I scroll down, there's my include.

125
00:08:16,020 --> 00:08:21,820
‫So I'm going to copy that and paste it right here at the top, just under tank edge.

126
00:08:21,900 --> 00:08:26,520
‫Now, just a side note in general, you're going to keep your class header file included at the top

127
00:08:26,520 --> 00:08:29,370
‫and includes for your components underneath that.

128
00:08:29,370 --> 00:08:30,750
‫So we have our spring arm.

129
00:08:30,750 --> 00:08:32,790
‫It's time to construct the camera.

130
00:08:32,790 --> 00:08:39,300
‫So we're going to say camera create default sub object, you camera component.

131
00:08:40,050 --> 00:08:45,240
‫And in the text macro, I'm going to call this simply camera.

132
00:08:45,240 --> 00:08:51,120
‫And for the camera I'm going to call setup attachment passing in spring arm.

133
00:08:51,390 --> 00:08:54,240
‫And of course I need the camera header file.

134
00:08:54,240 --> 00:08:59,820
‫So here's the unreal engine documentation and here where it says search documentation, I'm going to

135
00:08:59,820 --> 00:09:05,490
‫type you camera component and here I see you camera component.

136
00:09:05,490 --> 00:09:06,600
‫I'll select that.

137
00:09:06,600 --> 00:09:09,450
‫And here's the documentation for camera component.

138
00:09:09,450 --> 00:09:14,100
‫So I'll copy it to include paste it right here at the top of our file.

139
00:09:14,100 --> 00:09:15,930
‫And now we should be good.

140
00:09:15,960 --> 00:09:18,630
‫Okay, so let's go ahead and compile this.

141
00:09:18,810 --> 00:09:19,230
‫Okay.

142
00:09:19,230 --> 00:09:21,180
‫So I have a successful compile.

143
00:09:21,210 --> 00:09:24,210
‫Let's head back in the editor and here on -- Tank.

144
00:09:24,240 --> 00:09:30,690
‫Of course, we don't see anything because -- tank is derived from base -- and the components we

145
00:09:30,690 --> 00:09:33,510
‫just added, we added to the tank class.

146
00:09:33,510 --> 00:09:39,720
‫So BP -- tank is not going to get those because it's not derived from the tank class.

147
00:09:39,720 --> 00:09:44,910
‫Now we could go and create a new blueprint based on the tank class, but then we'd have to set up these

148
00:09:44,910 --> 00:09:46,710
‫components all over again.

149
00:09:46,710 --> 00:09:50,190
‫And I don't really feel like going through all that work a second time.

150
00:09:50,190 --> 00:09:55,080
‫There's an easier way we can repair this blueprint to the tank class.

151
00:09:55,080 --> 00:10:01,530
‫We do that by going up to class settings and in the details panel with class settings selected, we

152
00:10:01,530 --> 00:10:04,980
‫see class options and there's this parent class.

153
00:10:04,980 --> 00:10:10,800
‫The dropdown shows that it's set to base upon, but if we click on it, we can search for tank and choose

154
00:10:10,800 --> 00:10:13,200
‫tank as the base class.

155
00:10:13,200 --> 00:10:17,220
‫And now this blueprint is derived from the tank class.

156
00:10:17,220 --> 00:10:23,070
‫So we see that all of those properties we set with our components such as the mesh and the capsule size,

157
00:10:23,070 --> 00:10:24,630
‫they're all still there.

158
00:10:24,660 --> 00:10:27,090
‫Only now we see a camera.

159
00:10:27,390 --> 00:10:29,730
‫In fact, we have a spring arm and a camera.

160
00:10:29,730 --> 00:10:33,720
‫And if we select the spring arm now, we can see that red line.

161
00:10:33,720 --> 00:10:34,710
‫So this is great.

162
00:10:34,710 --> 00:10:38,880
‫So I could take this spring arm component and change its target arm length.

163
00:10:38,880 --> 00:10:46,650
‫If I like, I could set it to something like 600 and I can even change its rotation so that it's angling

164
00:10:46,650 --> 00:10:52,770
‫the camera down at the tank by selecting rotation mode and rotating it up a bit.

165
00:10:52,770 --> 00:10:58,500
‫Like So now I'd like to point out that you shouldn't change the camera's location.

166
00:10:58,530 --> 00:11:03,990
‫It might be tempting to select the camera and move it around in the world so that you position it and

167
00:11:03,990 --> 00:11:05,190
‫angle it just right.

168
00:11:05,190 --> 00:11:07,350
‫But this is not the correct way to do it.

169
00:11:07,350 --> 00:11:13,410
‫The correct way is to set the rotation and target arm length of the spring arm component.

170
00:11:13,410 --> 00:11:17,790
‫And the reason is you want that camera attached to the end of the spring arm.

171
00:11:17,790 --> 00:11:23,460
‫The spring arm has lots of different built in features such as shrinking in when the camera hits up

172
00:11:23,460 --> 00:11:29,430
‫against a wall to avoid obstacles, blocking the view to the pond and other things like that.

173
00:11:29,430 --> 00:11:35,070
‫So you're going to want that camera attached to the end of the spring arm and then adjust the spring

174
00:11:35,070 --> 00:11:39,990
‫arm rather than adjusting the camera's position and rotation.

175
00:11:40,110 --> 00:11:47,070
‫So in this video we created the tank class and we derived from base pond to inherit those qualities

176
00:11:47,070 --> 00:11:48,960
‫from the base pond class.

177
00:11:49,140 --> 00:11:56,100
‫We added a spring arm component and a camera component and exposed those to the editor using visible

178
00:11:56,100 --> 00:11:58,500
‫only and put them in their own category.

179
00:11:58,500 --> 00:12:03,900
‫So we're getting closer to the finished product step by step, and we'll continue developing this tank

180
00:12:03,900 --> 00:12:05,130
‫in the next lecture.

181
00:12:05,460 --> 00:12:06,510
‫I'll see you soon.

