‫Hello and welcome.
‫In this lecture, we are going to be adding a new component in C++ that we can add to our actors to
‫add in some functionality using some composition, essentially.
‫Let's dive in and see how this is done.
‫So I want to add a section of wall that disappears from view when we place an object on it.
‫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
‫dungeon wall in here.
‫And I think I want this one with a nice cut out section where I can stick a statuette.
‫So I'm going to drag this into the scene and I'm going to rotate it by 180 degrees and try and position
‫it accurately.
‫There we go.
‫Brought it down to the floor level and it's looking okay.
‫Now, what I want to do with this actor is I want to be able to add a component onto it that gives it
‫the capability of moving itself.
‫Now, we've dealt with components before.
‫We've added ones already created by Unreal, but we've never made our own in C++.
‫So that's what we're going to do in this lecture.
‫So what we're going to do is go to this add button and you can see there is an option within here to
‫create a new C++ component.
‫Now within here there are a couple of options for different types of components that we can inherit
‫from.
‫So the different types of components we can build.
‫There is an actor component, which is a component that just sits on an actor, any actor.
‫And then there's a scene component, which is an actor component that also adds in a transform and the
‫ability to attach to other scene components.
‫We don't need this functionality, so we're just going to go for the active component.
‫For now, we will be using scene components later on in the section though.
‫So let's go ahead and hit next.
‫Now we've got to name our component and we're going to call it simply the mover and we'll go ahead and
‫hit create class and instantly it opens up in Visual Studio for me and Visual Studio code and I can
‫see that there is a mover H and a mover CP just like we had with our actors.
‫Interesting to note that the prefix to this class is you previously with the actor.
‫The prefix had been a and the other thing to note is the name of the tic function is different with
‫a component.
‫Its function is called tic component instead, but otherwise it is the same.
‫And if we go over to the C++ class, you can see that there is a tic component function in here.
‫So I'd like to challenge you to log a message on TIC.
‫So you're going to add a new log message, add a component to the to an actor, add your new component
‫to some actor and see if it prints the message that you have written.
‫Pause the video and have a go.
‫Okay.
‫We'll come back.
‫So let's give this a stab.
‫So in the tick component, we're going to type you log to get the U log macro to come up.
‫We're leaving it as a display setting and in here I'm going to type in mover is ticking exclamation
‫points of course.
‫Let's go back into unreal.
‫Actually what you can do is do a control alt f 11 from any place.
‫Actually, you can do it in Visual Studio code and it brings up the live coding window automatically.
‫When it's complete, it brings you back over to the editor, just saves you an alt tab.
‫So what we can do now is you can see this actor does not have our new component on it.
‫So let's go to the add button and we're going to search for mover.
‫And then you can see there is a custom component called mover.
‫If I go ahead and add it, you can see adds it to a separate section to the static mesh components and
‫the other components at the top.
‫That's because these components here, the ones that are attached to each other, are all the scene
‫components, the ones that have transforms that can be attached.
‫Whereas the normal actor components, the more simple act components, go in a separate section down
‫at the bottom, and they don't.
‫They just go in the list, they don't get attached to each other.
‫So we've got the mover down here and the moment it doesn't do very much.
‫Let's bring up our output log and docket to the layout and let's go ahead and hit play in the game.
‫And you can see that we are indeed getting mover is taking displayed in our output log.
‫Great stuff.
‫We have created our first actor component in C++.
‫I'll see you in the next lecture.