﻿1
00:00:04,570 --> 00:00:05,590
‫Hello and welcome.

2
00:00:05,590 --> 00:00:10,120
‫In this lecture we are going to be covering lots of cool things, but most importantly, we're going

3
00:00:10,120 --> 00:00:14,050
‫to be looking at how we can child a actor to another actor.

4
00:00:14,050 --> 00:00:18,700
‫As you can see here, the rifle is a child of the shooter character and how we can make it such that

5
00:00:18,700 --> 00:00:24,460
‫the mesh there is actually attached to the hand of this skeletal mesh.

6
00:00:24,460 --> 00:00:28,180
‫As you can see, that gun is moving around with that player's hand.

7
00:00:28,180 --> 00:00:30,070
‫Let's dive in and see how it's done.

8
00:00:30,830 --> 00:00:37,820
‫So the first thing we want to do before putting our gun in the hands of this mesh is we want to remove

9
00:00:37,820 --> 00:00:40,460
‫or hide the gun that is currently there.

10
00:00:40,640 --> 00:00:46,910
‫Now, I find that the easiest way of doing this is to hide the bone that has the gun mesh.

11
00:00:46,910 --> 00:00:47,550
‫Let's have a look.

12
00:00:47,570 --> 00:00:53,900
‫So if we go over to the shooter character, BP would be a good entry point for this.

13
00:00:53,900 --> 00:00:57,010
‫And then I want to find go to the actual mesh here.

14
00:00:57,020 --> 00:00:57,950
‫We've got the skeletal mesh.

15
00:00:57,950 --> 00:01:04,760
‫And if I go to this skeleton, then we can find that this gun here, if I click on the gun, has got

16
00:01:04,760 --> 00:01:07,550
‫a bone leading up to it called the weapon.

17
00:01:07,550 --> 00:01:11,330
‫Bone and weapon underscore AR.

18
00:01:11,450 --> 00:01:17,150
‫And basically we want to hide this, but the easiest way to hide this across the board is going to be

19
00:01:17,150 --> 00:01:20,030
‫to do it in code and we're going to do it in C++.

20
00:01:20,030 --> 00:01:23,510
‫So the first thing is to get hold of the mesh component.

21
00:01:23,630 --> 00:01:30,380
‫The way to do this when you're on a character subclass is to call to get mesh cool.

22
00:01:30,380 --> 00:01:31,640
‫So we've got get mesh.

23
00:01:31,640 --> 00:01:35,420
‫Then with the mesh we want to hide the bone.

24
00:01:35,420 --> 00:01:44,570
‫There is handily a hide bone by name method and this actually exists on the parent of the skeletal mesh

25
00:01:44,570 --> 00:01:46,310
‫component, the skinned mesh component.

26
00:01:46,310 --> 00:01:48,080
‫Let's have a look at the header file briefly.

27
00:01:48,080 --> 00:01:49,340
‫Skinned mesh component.

28
00:01:50,240 --> 00:01:52,190
‫There is a couple of functions here.

29
00:01:52,190 --> 00:01:55,370
‫The one we're looking for is Hide Bone by name.

30
00:01:55,370 --> 00:01:57,110
‫So you can see the signature here.

31
00:01:57,110 --> 00:01:59,750
‫We've got the bone name comes in and f name.

32
00:01:59,750 --> 00:02:02,900
‫And then the second thing is this e fish body op.

33
00:02:02,990 --> 00:02:07,430
‫Now as far as I can tell, this isn't used in the code base, but we've got to provide it because it's

34
00:02:07,430 --> 00:02:08,660
‫there in the signature.

35
00:02:08,660 --> 00:02:10,460
‫So let's go ahead and use it.

36
00:02:10,460 --> 00:02:15,290
‫So Arrow going to do the hide bone by name.

37
00:02:15,410 --> 00:02:16,910
‫Unfortunately, my autocomplete is not working.

38
00:02:16,910 --> 00:02:23,480
‫That's a bug in 4.25 at the moment in V's code or to complete doesn't 100% want to work.

39
00:02:23,480 --> 00:02:24,590
‫But that's okay.

40
00:02:24,590 --> 00:02:26,810
‫We can learn to do it the manual way instead.

41
00:02:27,380 --> 00:02:32,060
‫Then we're going to want the name of the bone and I'll leave that up to you as an exercise to fill that

42
00:02:32,060 --> 00:02:33,200
‫out in a second.

43
00:02:33,500 --> 00:02:41,520
‫And then the second thing is we wanted that a phys op body thing and we're just going to go for that.

44
00:02:41,660 --> 00:02:45,200
‫That's an enum, so we're going to need to fill it out.

45
00:02:45,770 --> 00:02:49,370
‫I'm going to use F 12 to go to the definition and see what we have got.

46
00:02:49,550 --> 00:02:50,570
‫PBO None.

47
00:02:50,570 --> 00:02:53,030
‫Don't do anything that sounds like a sensible default.

48
00:02:53,030 --> 00:02:57,560
‫Let's go with that and then we'll use the semicolon to finish off our line right there.

49
00:02:57,980 --> 00:03:01,790
‫So let's compile this and see if we've got all the includes we need.

50
00:03:02,450 --> 00:03:02,810
‫Cool.

51
00:03:02,810 --> 00:03:07,040
‫Looks like it's working so we must have all the includes we need now.

52
00:03:07,070 --> 00:03:14,420
‫Let's what's your challenge is to put in the bone name give that a quick go mini challenge and we're

53
00:03:14,420 --> 00:03:19,760
‫coming back the bone name is weapon underscore R it was hinted at a little bit before weapon underscore

54
00:03:19,760 --> 00:03:21,350
‫R should do the trick.

55
00:03:21,350 --> 00:03:28,430
‫If we go ahead and recompile with that now and we hit play, you can see that he's no longer holding

56
00:03:28,430 --> 00:03:29,150
‫a gun.

57
00:03:29,150 --> 00:03:29,960
‫Fantastic.

58
00:03:29,960 --> 00:03:34,940
‫So the next thing is to put a different gun in his hand, the actor gun.

59
00:03:34,940 --> 00:03:37,460
‫So we need to go over to our skeleton.

60
00:03:37,460 --> 00:03:42,260
‫And what we want to do here is add in a new socket.

61
00:03:42,260 --> 00:03:46,730
‫So we're going to add in a socket in place of our weapon.

62
00:03:46,730 --> 00:03:48,110
‫R And what is a socket?

63
00:03:48,650 --> 00:03:53,540
‫A socket as it sounds like a plug socket is something that you can plug in.

64
00:03:53,570 --> 00:03:56,600
‫It's a point at which you can plug in other things.

65
00:03:56,600 --> 00:04:04,880
‫So you might want to be able to plug in, for example, a gun and you want it to be chided not to the

66
00:04:04,880 --> 00:04:12,320
‫mesh as a whole, but to a specific bone of that mesh, which means that it will move correctly with

67
00:04:12,320 --> 00:04:13,280
‫the character's arms.

68
00:04:13,280 --> 00:04:17,060
‫When he's doing an animation, when he's jogging around, it's going to look like it's attached to his

69
00:04:17,060 --> 00:04:22,340
‫hand rather than somewhere on it, not rigidly fixed to his torso.

70
00:04:22,340 --> 00:04:26,690
‫So we're going to add a child socket to a weapon.

71
00:04:27,050 --> 00:04:27,440
‫Do this.

72
00:04:27,440 --> 00:04:34,100
‫You go to the skeleton, you right click on the bone that you want to attach this socket to and you

73
00:04:34,100 --> 00:04:35,420
‫click add socket.

74
00:04:35,420 --> 00:04:38,780
‫And we're just going to call this one the weapon.

75
00:04:39,880 --> 00:04:40,900
‫Socket.

76
00:04:41,530 --> 00:04:46,550
‫I'm using camel case here as my convention, and that's what we're going to want to attach to.

77
00:04:46,580 --> 00:04:52,930
‫Now, you'll see where this comes in handy when we go to actually do the attachment for our gun.

78
00:04:53,320 --> 00:04:59,950
‫Now, the thing to note here is that we don't want to do a set up attachment as we would do in the constructor

79
00:04:59,980 --> 00:05:00,970
‫at runtime.

80
00:05:00,970 --> 00:05:05,080
‫When we do attachment, we have to use a different set of functions rather than the ones that we use

81
00:05:05,080 --> 00:05:06,010
‫in the constructor.

82
00:05:06,370 --> 00:05:11,830
‫And remember when I said that the only hierarchy here really is between scene components.

83
00:05:11,860 --> 00:05:16,430
‫Now, fortunately, we don't have to go in and get the root component of the gun and attach it.

84
00:05:16,450 --> 00:05:24,970
‫There is a helper method on the actor that allows us to do attachment and that is attached to component.

85
00:05:25,150 --> 00:05:27,040
‫So let's see where that's defined.

86
00:05:27,040 --> 00:05:33,100
‫If we go to look at the actor H header file and there's a couple of these, we want the one that lives

87
00:05:33,100 --> 00:05:41,320
‫under game framework and we're going to go and search in here for attach to component open brackets

88
00:05:41,320 --> 00:05:43,150
‫and find the actual declaration.

89
00:05:43,150 --> 00:05:43,720
‫Here it is.

90
00:05:43,870 --> 00:05:45,610
‫So what's this going to take in?

91
00:05:45,610 --> 00:05:50,080
‫It's going to take in a U.S. component, the parent that we want to attach to in this case, it's going

92
00:05:50,080 --> 00:05:53,110
‫to be our skeletal mesh of the character.

93
00:05:53,350 --> 00:05:55,930
‫The transform rules will get to this in just a second.

94
00:05:55,930 --> 00:06:00,780
‫And then there you go, the socket name, that's where on a skeletal mesh should we attach to?

95
00:06:00,800 --> 00:06:02,920
‫If it's a skeletal mesh, it'll attach to the socket.

96
00:06:02,920 --> 00:06:08,500
‫If it is not a skeletal mesh, it'll ignore the socket argument and just attach if it's a static mesh,

97
00:06:08,500 --> 00:06:09,190
‫for example.

98
00:06:09,370 --> 00:06:12,010
‫So we want to attach to get mesh.

99
00:06:12,700 --> 00:06:14,560
‫We have these transform rules.

100
00:06:14,560 --> 00:06:15,160
‫What are those?

101
00:06:15,160 --> 00:06:20,430
‫Let's click through F 12 to click through to their the different rules that are available.

102
00:06:20,440 --> 00:06:22,360
‫There's these are the preset rules.

103
00:06:22,360 --> 00:06:26,260
‫You can define your own, but you might as well use these preset ones.

104
00:06:26,260 --> 00:06:31,270
‫We've got keep relative transform, keep world transform snap to target not including scale will ignore

105
00:06:31,300 --> 00:06:31,450
‫these.

106
00:06:31,450 --> 00:06:37,120
‫Lastly, the main two to look out for are these first two and it basically means when we're attaching,

107
00:06:37,120 --> 00:06:43,570
‫should it stay the same place it was in the world, or should we use that world position as the new

108
00:06:43,570 --> 00:06:46,000
‫local position in our case?

109
00:06:46,000 --> 00:06:52,540
‫Because we want that gun to essentially be at zero zero, which would be its location in the world.

110
00:06:52,540 --> 00:06:55,510
‫We want to keep the relative transform, so let's do that.

111
00:06:55,510 --> 00:06:58,840
‫We're going to have the F transform rules keep relative transform.

112
00:07:00,840 --> 00:07:06,480
‫So I have transformed rooms rules colon colon and then should be let me see just copy over the keep

113
00:07:06,480 --> 00:07:10,950
‫relative transforms like so and then we want the socket.

114
00:07:10,950 --> 00:07:16,260
‫So again text macro here and then the socket name which was weapon socket.

115
00:07:17,840 --> 00:07:19,490
‫And finish off the line.

116
00:07:19,490 --> 00:07:21,870
‫That's going to set up the attachment.

117
00:07:21,890 --> 00:07:26,990
‫And now the final point is going to be to we want to set up.

118
00:07:27,660 --> 00:07:31,990
‫The gun to have this class as its owner.

119
00:07:32,010 --> 00:07:33,730
‫This is a bit of a subtle point.

120
00:07:33,750 --> 00:07:34,940
‫Why do we have an owner?

121
00:07:34,950 --> 00:07:38,230
‫I just said that there wasn't any hierarchy between actors.

122
00:07:38,250 --> 00:07:42,360
‫Well, there isn't in the sense of transforms, but they do have ownership.

123
00:07:42,360 --> 00:07:48,060
‫And where this ownership really comes into play is in multiplayer and in damage.

124
00:07:48,060 --> 00:07:52,260
‫So we'll see later on how we will need to know about the owner.

125
00:07:52,290 --> 00:08:00,090
‫It also allows the gun to know what is the owning character and it can use that to get references to

126
00:08:00,090 --> 00:08:02,010
‫the owning character later on.

127
00:08:02,040 --> 00:08:03,070
‫This will be useful.

128
00:08:03,090 --> 00:08:08,100
‫At the moment we don't particularly care, but we're just going to do it for completeness sake.

129
00:08:08,340 --> 00:08:09,400
‫Now actually name this wrong.

130
00:08:09,420 --> 00:08:14,760
‫It shouldn't be set up owner, but set owner to this because this is the actor that is the owner of

131
00:08:14,760 --> 00:08:15,270
‫the gun.

132
00:08:15,960 --> 00:08:16,640
‫Cool beans.

133
00:08:16,680 --> 00:08:19,680
‫Let's compile and see if this is working.

134
00:08:20,430 --> 00:08:21,700
‫The compiled successful.

135
00:08:21,700 --> 00:08:24,330
‫Let's dive in and play the game.

136
00:08:24,340 --> 00:08:25,000
‫Awesome.

137
00:08:25,000 --> 00:08:26,990
‫We have got a weapon in our hands.

138
00:08:27,010 --> 00:08:28,080
‫Is it in the right place?

139
00:08:28,090 --> 00:08:28,930
‫Let's have a look.

140
00:08:28,930 --> 00:08:32,680
‫Let's f eight out of here and have a look at the hand.

141
00:08:32,710 --> 00:08:33,640
‫Not quite.

142
00:08:33,640 --> 00:08:36,250
‫You can see that we could do a little bit of adjusting here.

143
00:08:36,250 --> 00:08:37,480
‫So that's what we're going to do.

144
00:08:37,480 --> 00:08:39,400
‫And this is a challenge for you.

145
00:08:39,400 --> 00:08:46,360
‫Basically, what you're going to try and do is find what the offsets should be on the mesh, such that

146
00:08:46,360 --> 00:08:52,520
‫this handle is actually inside our meshes Wraith character's hand.

147
00:08:52,540 --> 00:08:54,520
‫Pause the video and have a go at that.

148
00:08:54,820 --> 00:08:55,060
‫Okay.

149
00:08:55,060 --> 00:08:55,540
‫Welcome back.

150
00:08:55,540 --> 00:09:00,550
‫So I'm going to do this by selecting that mesh and trying to move it.

151
00:09:00,550 --> 00:09:06,820
‫I'm going to have to set the grid snap size in the viewport to a little bit less.

152
00:09:06,820 --> 00:09:12,100
‫And I'm going to try and zoom in as best I can on that hand.

153
00:09:13,340 --> 00:09:13,640
‫Okay.

154
00:09:13,640 --> 00:09:15,290
‫Bringing that down a little bit.

155
00:09:15,320 --> 00:09:16,550
‫I think that's good.

156
00:09:16,550 --> 00:09:17,090
‫Shout.

157
00:09:17,120 --> 00:09:21,620
‫Now let's go ahead and copy the location and open up.

158
00:09:21,620 --> 00:09:24,710
‫Go to the content browser and open up the BP rifle.

159
00:09:25,100 --> 00:09:33,410
‫Open the full blueprint editor, go to the mesh and stop simulating and paste the location that we had

160
00:09:33,410 --> 00:09:34,370
‫copied in there.

161
00:09:34,730 --> 00:09:35,210
‫Okay, cool.

162
00:09:35,210 --> 00:09:36,200
‫Copy that.

163
00:09:36,200 --> 00:09:39,110
‫And let's go and hit play.

164
00:09:40,050 --> 00:09:43,170
‫And let's see that it actually brought across the right thing.

165
00:09:43,290 --> 00:09:46,490
‫Fade out and zoom in.

166
00:09:46,500 --> 00:09:50,970
‫By the way, you can use the scroll wheel to slow down your movement when you're moving in this in this

167
00:09:50,970 --> 00:09:51,660
‫kind of way.

168
00:09:51,810 --> 00:09:52,530
‫Fantastic.

169
00:09:52,530 --> 00:09:56,910
‫Looks like he has got his hand directly on the handle.

170
00:09:57,640 --> 00:09:58,180
‫Awesome stuff.

171
00:09:58,180 --> 00:10:06,580
‫So we have learnt how we can child actors to other actors and how we can attach scene components to

172
00:10:06,580 --> 00:10:08,830
‫sockets of skeletal meshes.

173
00:10:08,830 --> 00:10:14,830
‫In the next lecture, we're going to be looking a little bit at shooting and how the this gun architecture

174
00:10:15,100 --> 00:10:18,250
‫basically dovetails into a shooting architecture.

175
00:10:18,250 --> 00:10:19,570
‫So I'll see you there.

