﻿1
00:00:04,110 --> 00:00:05,100
‫Welcome back.

2
00:00:05,370 --> 00:00:12,150
‫So we've already created a new capsule component pointer and forward declared it so we didn't have to

3
00:00:12,150 --> 00:00:15,390
‫include the header file in base upon h.

4
00:00:15,450 --> 00:00:22,140
‫It's now time to actually construct a capsule component sub object for our base POM And once we do that,

5
00:00:22,140 --> 00:00:25,410
‫we're going to set our root component to be the capsule.

6
00:00:26,380 --> 00:00:30,010
‫So how do we actually construct a you capsule component?

7
00:00:30,130 --> 00:00:31,750
‫The process is very unreal.

8
00:00:31,750 --> 00:00:37,300
‫Engine specific unreal engine has create default sub object.

9
00:00:37,450 --> 00:00:39,880
‫This is a template function.

10
00:00:39,910 --> 00:00:46,060
‫A template function adapts to the type chosen so we can choose a particular type and create default.

11
00:00:46,060 --> 00:00:48,460
‫Sub object will adapt to that type.

12
00:00:48,460 --> 00:00:53,290
‫We pass in the type that we wish to construct into create default sub object.

13
00:00:53,590 --> 00:00:57,210
‫Unlike a regular function, it has these angle brackets.

14
00:00:57,220 --> 00:01:00,400
‫This is where we pass in the type to construct.

15
00:01:00,430 --> 00:01:04,930
‫Now create default sub object also takes an argument in its parentheses.

16
00:01:04,930 --> 00:01:08,140
‫This is going to be a name that we assign to the sub object.

17
00:01:08,140 --> 00:01:12,220
‫This is different than the variable name and it's passed in as a string literal.

18
00:01:12,550 --> 00:01:13,960
‫So here's an example.

19
00:01:13,960 --> 00:01:17,170
‫Let's say we wish to create a u static mesh component.

20
00:01:17,350 --> 00:01:24,700
‫So we call create default sub object and end the angle brackets we pass in the type u static mesh component

21
00:01:24,700 --> 00:01:27,190
‫and in the parentheses we give it a name.

22
00:01:27,190 --> 00:01:31,300
‫Now you've already seen that for String Literals, you should use the text macro.

23
00:01:31,300 --> 00:01:35,200
‫So we're passing our string literal in using the text macro here.

24
00:01:35,230 --> 00:01:38,890
‫Now, as I mentioned, this is an internal name used by Unreal Engine.

25
00:01:38,920 --> 00:01:41,080
‫There are other functions that use this.

26
00:01:41,080 --> 00:01:45,130
‫For example, there's a function called get default sub object by name.

27
00:01:45,160 --> 00:01:50,890
‫It retrieves a sub object belonging to a particular object and you can call it passing in a particular

28
00:01:50,890 --> 00:01:54,190
‫name and it'll look for the sub object with that chosen name.

29
00:01:54,370 --> 00:01:59,440
‫So the overall function call to create default sub object looks like this.

30
00:01:59,620 --> 00:02:03,580
‫The type goes in the angle brackets and the name goes in the parentheses.

31
00:02:03,580 --> 00:02:09,460
‫Now create default sub object returns the address of the newly created component.

32
00:02:09,460 --> 00:02:15,910
‫So in our case, if we passed in use static mesh component as the type, then we get the address of

33
00:02:15,910 --> 00:02:21,970
‫a use static mesh component and we can store that in a pointer since pointers store addresses of things.

34
00:02:21,970 --> 00:02:26,050
‫So say we create a use static mesh component pointer called mesh.

35
00:02:26,050 --> 00:02:32,500
‫Then we can take that address returned by create default sub object and store that address in our mesh

36
00:02:32,500 --> 00:02:33,220
‫pointer.

37
00:02:33,700 --> 00:02:39,550
‫So now that you know how create default sub object works, you're going to use this to construct a capsule

38
00:02:39,550 --> 00:02:40,960
‫component object.

39
00:02:40,990 --> 00:02:47,230
‫You're going to do this in the base PON constructor use create default sub object to construct a capsule

40
00:02:47,230 --> 00:02:54,310
‫component pass in you capsule component and the angle brackets as the type to construct and pass in

41
00:02:54,310 --> 00:02:58,540
‫capsule collider wrapped in a text macro in the parentheses.

42
00:02:58,900 --> 00:03:03,880
‫Pause the video and add this to base pont CP in the constructor now.

43
00:03:07,720 --> 00:03:08,170
‫Okay.

44
00:03:08,170 --> 00:03:09,430
‫So we're here in Bass Pond.

45
00:03:09,640 --> 00:03:13,270
‫CP and we'd like to construct a capsule component.

46
00:03:13,270 --> 00:03:21,400
‫So we're going to take our capsule comp variable and assign the value returned by create default sub

47
00:03:21,400 --> 00:03:22,150
‫object.

48
00:03:22,510 --> 00:03:29,620
‫Now, as we've seen, this template function has angle brackets as well as parentheses, and we saw

49
00:03:29,620 --> 00:03:34,480
‫that the type goes in the angle brackets, we're going to use U capsule component.

50
00:03:34,570 --> 00:03:41,320
‫And for the parentheses we're going to use the text macro and we're going to call this capsule collider.

51
00:03:42,160 --> 00:03:43,210
‫And there we go.

52
00:03:43,390 --> 00:03:48,870
‫Now we're using you capsule component to construct an object of this type.

53
00:03:48,880 --> 00:03:52,450
‫And when we use a type, we include its header file.

54
00:03:52,960 --> 00:03:56,290
‫Now let's see what happens when we attempt to compile.

55
00:03:56,320 --> 00:04:00,560
‫Now again, you can use live coding or you can compile here in VZ code.

56
00:04:00,580 --> 00:04:03,820
‫I'm going to be compiling here in VTS code throughout this section.

57
00:04:03,820 --> 00:04:09,130
‫So you can just know that when I compile I have closed the Unreal Engine editor and I'm just compiling

58
00:04:09,130 --> 00:04:09,550
‫from here.

59
00:04:09,550 --> 00:04:14,770
‫I'd like to see the error message here and VTS code now attempting to compile this here.

60
00:04:14,770 --> 00:04:17,950
‫We get a different error than the one we saw in the last video.

61
00:04:17,980 --> 00:04:21,430
‫Use of undefined type u capsule component.

62
00:04:21,610 --> 00:04:27,970
‫This time we're trying to use the U capsule component type here in the CPP file to construct an object.

63
00:04:28,180 --> 00:04:33,190
‫Here's the error code in case you wish to Google this particular type of error for more information.

64
00:04:33,610 --> 00:04:38,470
‫So now we've seen two different types of compilation errors in this section of the course, and we know

65
00:04:38,470 --> 00:04:40,150
‫the cause of this particular error.

66
00:04:40,150 --> 00:04:42,700
‫We haven't included you capsule component.

67
00:04:42,820 --> 00:04:49,330
‫Now here's U capsule component in Unreal Engine's documentation and here's the include that we need

68
00:04:49,330 --> 00:04:50,530
‫for this type.

69
00:04:50,530 --> 00:04:56,710
‫So I'm going to copy this and paste it here at the top of Base Pond CPP.

70
00:04:56,740 --> 00:05:02,890
‫Now if I attempt to compile again, compilation is successful, we see no errors.

71
00:05:03,100 --> 00:05:04,870
‫I'm going to close the terminal now.

72
00:05:04,990 --> 00:05:07,510
‫So we've created the capsule component.

73
00:05:07,540 --> 00:05:11,920
‫The next thing I'd like to do is make sure the capsule component is the root.

74
00:05:11,950 --> 00:05:18,890
‫Now we saw how to assign a component as the root and blueprints by clicking and dragging in C++.

75
00:05:18,910 --> 00:05:20,430
‫It's also pretty easy.

76
00:05:20,440 --> 00:05:26,590
‫We simply take that root component variable and assign it the value of capsule comp.

77
00:05:26,800 --> 00:05:30,520
‫Now we've specified that capsule comp should be the root component.

78
00:05:30,790 --> 00:05:32,290
‫Let's compile this again.

79
00:05:32,470 --> 00:05:36,910
‫And now after a successful compilation, I'd like to hop back into the editor.

80
00:05:37,000 --> 00:05:37,350
‫Okay.

81
00:05:37,360 --> 00:05:42,570
‫I've opened up the editor and I'm going to take my base --, C++ class and drag one in.

82
00:05:42,580 --> 00:05:44,100
‫And now check this out.

83
00:05:44,110 --> 00:05:46,330
‫We see a capsule component.

84
00:05:46,420 --> 00:05:48,260
‫Now in the world, out liner.

85
00:05:48,280 --> 00:05:53,350
‫It shows that the base -- that I just dragged in is selected now just above search in the details

86
00:05:53,350 --> 00:05:53,870
‫panel.

87
00:05:53,890 --> 00:05:58,660
‫I can drag this down and see all components on this base --.

88
00:05:58,660 --> 00:06:03,430
‫And all we see is this capsule comp because that's the only component that it has.

89
00:06:03,520 --> 00:06:09,490
‫So we've now added our capsule component and we see the result of that when we actually add an instance

90
00:06:09,490 --> 00:06:13,120
‫of this class into the world in the Unreal Engine Editor.

91
00:06:13,760 --> 00:06:19,970
‫So in summary, we've learned how to construct a capsule component from C++, and we made it the root

92
00:06:19,970 --> 00:06:25,070
‫component by assigning the value of the root component variable to capsule comp.

93
00:06:25,100 --> 00:06:29,600
‫In the next video, we're going to add more components to our base in C++ class.

94
00:06:29,810 --> 00:06:30,770
‫I'll see you then.

