﻿1
00:00:04,500 --> 00:00:05,580
‫Hello and welcome.

2
00:00:05,580 --> 00:00:13,440
‫In this lecture, we are going to be adding a new component in C++ that we can add to our actors to

3
00:00:13,440 --> 00:00:17,940
‫add in some functionality using some composition, essentially.

4
00:00:17,940 --> 00:00:19,980
‫Let's dive in and see how this is done.

5
00:00:20,370 --> 00:00:28,560
‫So I want to add a section of wall that disappears from view when we place an object on it.

6
00:00:28,560 --> 00:00:34,710
‫So what I'm going to do here is I'm going to go to the content draw and I'm going to search for the

7
00:00:34,710 --> 00:00:38,370
‫dungeon wall in here.

8
00:00:38,730 --> 00:00:44,250
‫And I think I want this one with a nice cut out section where I can stick a statuette.

9
00:00:44,250 --> 00:00:53,610
‫So I'm going to drag this into the scene and I'm going to rotate it by 180 degrees and try and position

10
00:00:53,610 --> 00:00:54,840
‫it accurately.

11
00:00:54,870 --> 00:00:55,350
‫There we go.

12
00:00:55,350 --> 00:00:58,590
‫Brought it down to the floor level and it's looking okay.

13
00:00:58,770 --> 00:01:06,630
‫Now, what I want to do with this actor is I want to be able to add a component onto it that gives it

14
00:01:06,630 --> 00:01:09,540
‫the capability of moving itself.

15
00:01:09,840 --> 00:01:12,240
‫Now, we've dealt with components before.

16
00:01:12,240 --> 00:01:17,220
‫We've added ones already created by Unreal, but we've never made our own in C++.

17
00:01:17,220 --> 00:01:18,930
‫So that's what we're going to do in this lecture.

18
00:01:18,930 --> 00:01:24,390
‫So what we're going to do is go to this add button and you can see there is an option within here to

19
00:01:24,390 --> 00:01:27,780
‫create a new C++ component.

20
00:01:28,050 --> 00:01:33,030
‫Now within here there are a couple of options for different types of components that we can inherit

21
00:01:33,030 --> 00:01:33,330
‫from.

22
00:01:33,330 --> 00:01:35,280
‫So the different types of components we can build.

23
00:01:35,280 --> 00:01:41,100
‫There is an actor component, which is a component that just sits on an actor, any actor.

24
00:01:41,280 --> 00:01:47,010
‫And then there's a scene component, which is an actor component that also adds in a transform and the

25
00:01:47,010 --> 00:01:49,380
‫ability to attach to other scene components.

26
00:01:49,380 --> 00:01:52,860
‫We don't need this functionality, so we're just going to go for the active component.

27
00:01:52,860 --> 00:01:56,460
‫For now, we will be using scene components later on in the section though.

28
00:01:56,460 --> 00:01:58,200
‫So let's go ahead and hit next.

29
00:01:58,200 --> 00:02:05,250
‫Now we've got to name our component and we're going to call it simply the mover and we'll go ahead and

30
00:02:05,250 --> 00:02:12,540
‫hit create class and instantly it opens up in Visual Studio for me and Visual Studio code and I can

31
00:02:12,540 --> 00:02:17,490
‫see that there is a mover H and a mover CP just like we had with our actors.

32
00:02:17,490 --> 00:02:22,770
‫Interesting to note that the prefix to this class is you previously with the actor.

33
00:02:22,770 --> 00:02:28,380
‫The prefix had been a and the other thing to note is the name of the tic function is different with

34
00:02:28,380 --> 00:02:28,980
‫a component.

35
00:02:28,980 --> 00:02:34,530
‫Its function is called tic component instead, but otherwise it is the same.

36
00:02:34,530 --> 00:02:41,040
‫And if we go over to the C++ class, you can see that there is a tic component function in here.

37
00:02:41,040 --> 00:02:44,550
‫So I'd like to challenge you to log a message on TIC.

38
00:02:44,550 --> 00:02:51,390
‫So you're going to add a new log message, add a component to the to an actor, add your new component

39
00:02:51,390 --> 00:02:55,800
‫to some actor and see if it prints the message that you have written.

40
00:02:55,800 --> 00:02:57,780
‫Pause the video and have a go.

41
00:03:00,750 --> 00:03:01,230
‫Okay.

42
00:03:01,230 --> 00:03:01,920
‫We'll come back.

43
00:03:01,920 --> 00:03:03,220
‫So let's give this a stab.

44
00:03:03,240 --> 00:03:09,540
‫So in the tick component, we're going to type you log to get the U log macro to come up.

45
00:03:10,050 --> 00:03:17,880
‫We're leaving it as a display setting and in here I'm going to type in mover is ticking exclamation

46
00:03:17,880 --> 00:03:18,870
‫points of course.

47
00:03:18,870 --> 00:03:20,520
‫Let's go back into unreal.

48
00:03:20,550 --> 00:03:27,570
‫Actually what you can do is do a control alt f 11 from any place.

49
00:03:27,570 --> 00:03:31,470
‫Actually, you can do it in Visual Studio code and it brings up the live coding window automatically.

50
00:03:31,470 --> 00:03:35,520
‫When it's complete, it brings you back over to the editor, just saves you an alt tab.

51
00:03:35,670 --> 00:03:40,680
‫So what we can do now is you can see this actor does not have our new component on it.

52
00:03:40,680 --> 00:03:46,050
‫So let's go to the add button and we're going to search for mover.

53
00:03:46,050 --> 00:03:48,660
‫And then you can see there is a custom component called mover.

54
00:03:48,660 --> 00:03:53,670
‫If I go ahead and add it, you can see adds it to a separate section to the static mesh components and

55
00:03:53,670 --> 00:03:55,050
‫the other components at the top.

56
00:03:55,350 --> 00:04:00,150
‫That's because these components here, the ones that are attached to each other, are all the scene

57
00:04:00,150 --> 00:04:04,080
‫components, the ones that have transforms that can be attached.

58
00:04:04,080 --> 00:04:09,660
‫Whereas the normal actor components, the more simple act components, go in a separate section down

59
00:04:09,660 --> 00:04:10,590
‫at the bottom, and they don't.

60
00:04:10,590 --> 00:04:13,050
‫They just go in the list, they don't get attached to each other.

61
00:04:13,050 --> 00:04:17,130
‫So we've got the mover down here and the moment it doesn't do very much.

62
00:04:17,130 --> 00:04:24,210
‫Let's bring up our output log and docket to the layout and let's go ahead and hit play in the game.

63
00:04:24,210 --> 00:04:30,090
‫And you can see that we are indeed getting mover is taking displayed in our output log.

64
00:04:30,120 --> 00:04:30,840
‫Great stuff.

65
00:04:30,840 --> 00:04:34,050
‫We have created our first actor component in C++.

66
00:04:34,050 --> 00:04:35,700
‫I'll see you in the next lecture.

