﻿1
00:00:04,320 --> 00:00:05,670
‫Hey, welcome back.

2
00:00:05,700 --> 00:00:11,280
‫In this video, we're going to talk about components and how our base pawn is going to want some of

3
00:00:11,280 --> 00:00:17,490
‫these components for things like collisions and visual representation, like meshes, as well as a spawn

4
00:00:17,490 --> 00:00:20,740
‫point from which our projectiles will appear.

5
00:00:20,760 --> 00:00:26,070
‫We're going to talk about how components, support, attachment so we can attach various components

6
00:00:26,070 --> 00:00:32,760
‫to each other, as well as how our pawn has a root component which stores the transform information

7
00:00:32,760 --> 00:00:33,930
‫for the --.

8
00:00:34,200 --> 00:00:40,770
‫Now we've already created our first C++ class called Base --, and now we're ready to start adding

9
00:00:40,770 --> 00:00:42,630
‫some things to the base --.

10
00:00:42,690 --> 00:00:50,090
‫The base -- is going to need some components, such as meshes for the base and turret of the tank.

11
00:00:50,100 --> 00:00:55,470
‫C In our meshes folder, we have a tank base, we have a tank turret and for the tower we also have

12
00:00:55,470 --> 00:00:57,210
‫a base and a turret.

13
00:00:57,540 --> 00:01:00,480
‫So we're going to need a couple of mesh components.

14
00:01:00,480 --> 00:01:06,930
‫We're also going to want a capsule component to handle collisions so our tank and turret won't be passing

15
00:01:06,930 --> 00:01:08,000
‫through each other.

16
00:01:08,010 --> 00:01:10,890
‫Now, let's talk about components for a second.

17
00:01:11,040 --> 00:01:17,180
‫When we add a component to a class, we need to decide what class that component should be.

18
00:01:17,190 --> 00:01:19,830
‫Now, one choice is a scene component.

19
00:01:20,070 --> 00:01:26,880
‫The you seen component class has some properties, such as it has a transform, meaning it has a location,

20
00:01:26,880 --> 00:01:28,380
‫a rotation and such.

21
00:01:28,440 --> 00:01:30,330
‫It also supports attachment.

22
00:01:30,330 --> 00:01:34,530
‫This means we can attach other components to a scene component.

23
00:01:34,530 --> 00:01:36,900
‫We'll learn more about how that works later.

24
00:01:37,020 --> 00:01:42,780
‫And a scene component does not have a visual representation, meaning it doesn't have a mesh or anything

25
00:01:42,780 --> 00:01:43,410
‫like that.

26
00:01:43,410 --> 00:01:45,570
‫We can't actually see it in the game.

27
00:01:45,570 --> 00:01:51,450
‫Now there are some other classes in Unreal Engine that are derived from scene component, such as a

28
00:01:51,450 --> 00:01:52,650
‫capsule component.

29
00:01:52,680 --> 00:01:59,130
‫The YOU capsule component class is made to handle collision and that's just about all it's good for.

30
00:01:59,130 --> 00:02:05,190
‫We use the capsule component so that our -- does not fall through the floor or move through walls

31
00:02:05,190 --> 00:02:06,240
‫and things like that.

32
00:02:06,240 --> 00:02:11,850
‫Now also derived from the scene component class is the static mesh component.

33
00:02:12,150 --> 00:02:19,110
‫The use static mesh component class gives us the ability to have a visual representation, specifically

34
00:02:19,140 --> 00:02:25,830
‫a mesh that will belong to our -- class that we can see in the world as we're moving it around.

35
00:02:26,100 --> 00:02:32,550
‫Now, by default, our -- class already has a component, it's called root component.

36
00:02:32,550 --> 00:02:37,440
‫Let's go back into VS code and see if we can find this root component.

37
00:02:37,440 --> 00:02:43,170
‫So I'm here in Base Pont CP and I'm just going to click anywhere such as here in the constructor and

38
00:02:43,170 --> 00:02:48,270
‫I'm going to type root component just like that.

39
00:02:48,450 --> 00:02:56,460
‫Now I'm going to right click on this and click go to definition and all of a sudden we have actor opened

40
00:02:56,460 --> 00:02:56,850
‫up.

41
00:02:56,850 --> 00:03:04,740
‫And here in actors in a protected section we see a you seen component pointer called root component.

42
00:03:05,190 --> 00:03:10,470
‫So this variable called root component exists on the actor class.

43
00:03:10,470 --> 00:03:15,690
‫So anything derived from actor will inherit this root component variable.

44
00:03:16,260 --> 00:03:20,820
‫That means our base -- also has this root component variable.

45
00:03:20,850 --> 00:03:27,360
‫So whenever we think about the location of a particular --, we're actually talking about the location

46
00:03:27,360 --> 00:03:33,870
‫information stored in the transform of that root component, which is a scene component.

47
00:03:33,870 --> 00:03:36,690
‫So scene components have their own transform.

48
00:03:36,720 --> 00:03:42,930
‫I'm going to go ahead and close Actor H and delete this line that I added to the constructor of base

49
00:03:42,930 --> 00:03:43,500
‫--.

50
00:03:43,890 --> 00:03:50,640
‫So we know that our -- has this root component and it's type is you seen component, which means our

51
00:03:50,640 --> 00:03:52,770
‫-- has a transform.

52
00:03:52,770 --> 00:03:57,210
‫But we also know that this root component does not have a visual representation.

53
00:03:57,210 --> 00:03:58,380
‫It's invisible.

54
00:03:58,380 --> 00:04:05,820
‫However, we can reassign that root component with some other object whose type derives from seen component.

55
00:04:05,850 --> 00:04:07,350
‫Now we saw that the U.

56
00:04:07,350 --> 00:04:10,500
‫Capsule component class is derived from scene component.

57
00:04:10,500 --> 00:04:17,670
‫So if we create a capsule, we can assign that to be the root instead of that default scene component.

58
00:04:17,820 --> 00:04:21,360
‫Now we mentioned that scene components, support attachment.

59
00:04:21,360 --> 00:04:26,790
‫This means we can create other components and attach them to a scene component.

60
00:04:26,790 --> 00:04:32,730
‫So if we create a static mesh component, for example, called base mesh, we can attach it to the root

61
00:04:32,730 --> 00:04:33,510
‫component.

62
00:04:33,540 --> 00:04:40,080
‫Now, because a static mesh component is derived from the scene component class, it also supports attachment.

63
00:04:40,080 --> 00:04:44,760
‫So if we create another mesh, we can attach it to the first mesh.

64
00:04:44,760 --> 00:04:50,760
‫So we could create a current mesh static mesh component and attach it to the base mesh component.

65
00:04:50,790 --> 00:04:53,940
‫Now we can also just create new scene components.

66
00:04:53,940 --> 00:05:00,690
‫For example, if we want a scene component that we can call projectile spawn point, we can attach it

67
00:05:00,690 --> 00:05:01,890
‫to the turret mesh.

68
00:05:01,890 --> 00:05:03,750
‫Now why would we just create a scene?

69
00:05:03,860 --> 00:05:04,510
‫Component.

70
00:05:04,520 --> 00:05:07,020
‫We can't give it its own visual representation.

71
00:05:07,040 --> 00:05:13,280
‫Well, if we need a spawn point, a location from which we'd like to spawn projectiles, a scene component

72
00:05:13,280 --> 00:05:19,100
‫is perfect for this because it has its own transform, its own location, rotation, etc. and we can

73
00:05:19,100 --> 00:05:22,460
‫use that as a point to spawn projectiles from.

74
00:05:22,490 --> 00:05:28,880
‫So after assigning a capsule to be the root component, our root component will now have the U.

75
00:05:28,910 --> 00:05:36,560
‫Capsule component class type and the base mesh and the turret mesh would be static mesh components and

76
00:05:36,560 --> 00:05:40,460
‫our projectile spawn point would be a U seen component.

77
00:05:40,880 --> 00:05:46,340
‫Now let's talk about this attachment thing for a second, because these things are all attached to each

78
00:05:46,340 --> 00:05:46,670
‫other.

79
00:05:46,700 --> 00:05:52,850
‫This means that as the root component moves around in space, everything that's attached to it will

80
00:05:52,850 --> 00:05:54,350
‫move along with it.

81
00:05:54,740 --> 00:05:59,640
‫But the base mesh itself can move relative to the root.

82
00:05:59,660 --> 00:06:06,260
‫For example, it can rotate around and everything attached to the base mesh will follow along.

83
00:06:06,680 --> 00:06:14,210
‫Likewise, we have this turret mesh attached to the base mesh and it itself can move independently from

84
00:06:14,210 --> 00:06:15,020
‫the base mesh.

85
00:06:15,050 --> 00:06:21,320
‫For example, if we rotate the turret mesh, it'll rotate and anything attached to it, such as the

86
00:06:21,320 --> 00:06:25,270
‫scene component will follow along with the turret mesh.

87
00:06:25,280 --> 00:06:30,560
‫So the scene component will move around along with the turret mesh as it rotates.

88
00:06:30,560 --> 00:06:35,450
‫But of course if we wanted to, we could move the scene component relative to the turret mesh.

89
00:06:35,630 --> 00:06:40,550
‫And since nothing is attached to the scene component, well, there's nothing to follow along with it.

90
00:06:40,580 --> 00:06:46,330
‫Now let's take a look at how components work in blueprints, what the content folder selected.

91
00:06:46,340 --> 00:06:50,930
‫I'm going to right click and select Blueprint Class to create a new blueprint.

92
00:06:50,960 --> 00:06:59,000
‫Let's choose actor and call this Components Actor now double click components actor and notice that

93
00:06:59,000 --> 00:07:01,020
‫we have default scene root.

94
00:07:01,040 --> 00:07:05,040
‫This represents that root component variable we saw in C++.

95
00:07:05,060 --> 00:07:11,780
‫Now, if we want, we can add new components by clicking the add button and selecting the type of component

96
00:07:11,780 --> 00:07:12,770
‫we'd like to add.

97
00:07:12,770 --> 00:07:15,790
‫Search for Capsule and Select Capsule Collision.

98
00:07:15,800 --> 00:07:17,900
‫This is a capsule component.

99
00:07:17,900 --> 00:07:20,320
‫It's C++ counterpart is the U.

100
00:07:20,330 --> 00:07:21,780
‫Capsule component class.

101
00:07:21,800 --> 00:07:24,260
‫Notice it's just under the default scene.

102
00:07:24,260 --> 00:07:27,440
‫Root This indicates that it's attached to this scene.

103
00:07:27,440 --> 00:07:30,350
‫Root We can continue adding more components.

104
00:07:30,350 --> 00:07:36,620
‫For example, if you select Kub, then a static mesh component will be added and it's static mesh property

105
00:07:36,620 --> 00:07:40,430
‫in the details panel will be automatically set to a cube.

106
00:07:40,430 --> 00:07:41,460
‫Static mesh.

107
00:07:41,480 --> 00:07:46,420
‫Now notice in the components panel, the cube is just under the capsule.

108
00:07:46,430 --> 00:07:52,280
‫If we click the dropdown next to it, we no longer see the cube here so we can collapse this to hide

109
00:07:52,280 --> 00:07:55,490
‫any objects that are attached to a given component.

110
00:07:55,490 --> 00:08:01,340
‫Now we can reassign the root component by clicking and dragging one of our components on to the default

111
00:08:01,340 --> 00:08:01,970
‫scene root.

112
00:08:01,970 --> 00:08:07,370
‫For example, if I click and drag the capsule on to the default scene root, it now becomes the root

113
00:08:07,370 --> 00:08:08,210
‫component.

114
00:08:08,210 --> 00:08:11,870
‫So we've reassigned root component to this capsule component.

115
00:08:11,870 --> 00:08:14,180
‫We can also assign attachment.

116
00:08:14,180 --> 00:08:16,430
‫Let's click add and select sphere.

117
00:08:16,430 --> 00:08:21,200
‫Now by default, the sphere is attached to the capsule just like the cube static mesh.

118
00:08:21,200 --> 00:08:27,560
‫But if I click and drag sphere on to the cube, the sphere is now attached directly to the cube.

119
00:08:27,560 --> 00:08:33,530
‫If we click the sphere and drag it on to the capsule, we have the option to either make new root or

120
00:08:33,530 --> 00:08:34,340
‫attach.

121
00:08:34,700 --> 00:08:39,680
‫If we select attach, the sphere will just be attached to the capsule again.

122
00:08:39,950 --> 00:08:46,010
‫But if we were to select make new root, the sphere would become the root component instead.

123
00:08:46,550 --> 00:08:52,910
‫So we not only have control over creation of new components and how they're attached, but we can also

124
00:08:52,910 --> 00:08:54,770
‫reassign that root component.

125
00:08:55,130 --> 00:09:00,410
‫Let's go ahead and select the sphere by left clicking hold shift and left click the cube to select it

126
00:09:00,410 --> 00:09:04,850
‫as well and hit delete to remove these components.

127
00:09:05,180 --> 00:09:10,520
‫Now for your challenge, I'd like you to become a little bit more familiar with components in blueprints.

128
00:09:10,520 --> 00:09:12,980
‫Add a couple of components to our actor.

129
00:09:12,980 --> 00:09:17,510
‫We already have a capsule component and that's currently the root component.

130
00:09:17,510 --> 00:09:23,960
‫Add a static mesh component and for its static mesh, assign the tank base, then add a second static

131
00:09:23,960 --> 00:09:27,950
‫mesh component and assign the tank turret as its static mesh.

132
00:09:27,980 --> 00:09:34,040
‫Make sure to attach the base mesh to the capsule and attach the turret mesh to the base mesh.

133
00:09:34,040 --> 00:09:40,640
‫Now once you've done this move and scale the base mesh and observe how the attached turret mesh behaves,

134
00:09:40,640 --> 00:09:42,800
‫pause the video and give this a try.

135
00:09:45,720 --> 00:09:46,080
‫Okay.

136
00:09:46,080 --> 00:09:48,780
‫So I'm going to click Add and select static mesh.

137
00:09:48,780 --> 00:09:53,550
‫Now in the details panel, I'm going to set the static mesh to the tank base mesh.

138
00:09:53,550 --> 00:09:57,150
‫Next, I'm going to click Add and select static mesh again.

139
00:09:57,150 --> 00:10:02,760
‫Notice it's automatically attached to the first static mesh because that's what I still had selected

140
00:10:02,760 --> 00:10:03,840
‫in the details panel.

141
00:10:03,840 --> 00:10:06,840
‫I'm going to set the static mesh to the tank turret.

142
00:10:06,870 --> 00:10:12,330
‫Now with the first static mesh selected, I'm going to move it around and notice that the second static

143
00:10:12,330 --> 00:10:15,330
‫mesh that's attached to it is moving along with it.

144
00:10:15,330 --> 00:10:18,750
‫The same works for rotation and scale.

145
00:10:18,750 --> 00:10:22,770
‫As I scale it up, the attached mesh gets bigger as well.

146
00:10:23,130 --> 00:10:29,400
‫So we've talked about components and we've seen how we can attach components to other components and

147
00:10:29,400 --> 00:10:30,480
‫moving and scaling.

148
00:10:30,480 --> 00:10:34,290
‫One component affects the other components that are attached to it.

149
00:10:34,290 --> 00:10:41,100
‫We also saw that pons inherit a root component from the actor class and this is the object that stores

150
00:10:41,100 --> 00:10:43,650
‫the transform information for the pawn.

151
00:10:43,980 --> 00:10:48,270
‫We'll learn about how to create components in C++ and the lectures to come.

152
00:10:48,840 --> 00:10:50,250
‫I'll see you in the next video.

