‫Hey.
‫Welcome back.
‫Now, we've already created a base -- C++ class.
‫In this video, we're going to derive from that class to create a new child class based on base --.
‫So let's discuss why we'd want to do such a thing.
‫So we have this base -- class and we know that we're going to have two different classes that derive
‫from base --.
‫We're going to have our tank and we're going to have the tower.
‫Now, the base -- contains meshes, a capsule as well as a spawn point.
‫And these are things that the Tank and tower can both inherit.
‫But the tank and tower are also going to have some functionality that differs from each other.
‫For one, our tank is going to move around in the world and it's also going to be controlled by the
‫player.
‫So it'll need to be configured to take input from the keyboard and mouse.
‫The tower, on the other hand, is just going to sit there.
‫It has no need for any input from the player as its actions will all be controlled by code.
‫So because the tank and tower will behave differently, we're going to make use of inheritance to create
‫child classes of base -- so we can inherit what they have in common and then add to each class those
‫features that will be different.
‫So we're back here in the editor and I'm going to go into our C++ classes, Tune Tank's folder where
‫we have our base -- class and this will be the class that we're deriving from.
‫Now we can right click here and select create C++ class derived from base --.
‫So let's choose that and I'm going to allow it to stick this class in the same source slash tune tanks
‫folder as base --.
‫And for the name of this, I'm going to call it tank.
‫So our tank class will be the class for our actual tank -- that we're controlling and moving around
‫in the world.
‫So let's click create class.
‫Okay, so we've compiled and vs code has opened up with our new tank file and we also have Tank CP.
‫Now these are pretty bare.
‫There's really nothing here, but even though we can't see them, we have inherited some things from
‫the base -- class.
‫We do have those components that we've added to base --.
‫Even though those are private variables, they still exist in this class.
‫So now that we've created our tank class, let's talk about a couple of things.
‫The tank will need that the turret will not.
‫Well, since we're going to be controlling the tank, we're going to need a way to focus on the tank
‫as it's rolling around throughout the level.
‫Now, in this picture, this here is a camera component.
‫It's C++ class is you camera component.
‫And this red line here is called a spring arm component and its C++ class is you spring arm component.
‫Adding these components to a -- allows us to view the -- from the point of view of the camera.
‫And if the camera and its spring arm are attached to the -- in some way, they will follow the --
‫around in the world.
‫Now, back here in the editor, if we go back to our --'s folder and open BP -- tank, we can click
‫the viewport so we can see everything.
‫And then we can select the capsule comp and click add and select spring arm.
‫This is a spring arm component.
‫It looks like a red line.
‫Now with our spring arm component selected, we can add another component and choose camera.
‫Now, once we've added the camera attached to the spring arm, we now have a way to see from the point
‫of view of the camera once we actually start controlling the --.
‫Now the spring arm is pretty useful.
‫It has this target arm length and if you adjust it, you'll see that the camera adjusts along with the
‫spring arm.
‫So this is a way to control how far away the camera is from the --.
‫So these are definitely things that we want on our -- class, but we're going to add them from the
‫C++ side rather than just adding them here in the blueprint.
‫So I'm going to delete those.
‫So for your challenge, I'd like you to add some things to the tank class.
‫For one, we need a spring arm component and a camera component, so create these variables and make
‫them pointers.
‫Go ahead and make a public and a private section and put these variables in the private section.
‫Now we'll need these to be U properties, so give them you property macros and fill in those macros
‫with the appropriate specifiers based on what you've learned in the previous lectures.
‫Now, once you've created these variables, create a constructor and put this in the public section
‫and define it in the CP file, and then inside the constructor construct our camera and spring arm components
‫using create default sub object.
‫Make sure to use setup attachment to attach these components to something.
‫We'd like our spring arm component attached to the root component.
‫So use root component and set setup attachment and for the camera, attach it to the spring arm.
‫You can refer back to the base -- class.
‫A Remind yourself what the code looks like to do these things.
‫Go ahead and pause the video and add these things to the tank class.
‫All right.
‫So we're here in Tank.
‫Now, first things first.
‫I'd like to have a public section and a private section.
‫So the private section will be where we add these two new components.
‫We're going to want a U spring arm component, which will be a pointer, and we can call this spring
‫arm.
‫And we'll also need a new camera component and we'll call this camera.
‫That's okay.
‫If your names are slightly different.
‫Now, right off the bat, I'm seeing the IntelliSense errors here, which means I'm going to need to
‫forward declare these.
‫So I'm going to use class with spring arm and class with camera.
‫And now these are forward declared.
‫Now we need our new properties.
‫So let's add the new property macros.
‫And inside the property macro we're going to want to have some specifiers.
‫These will be visible anywhere as we saw that the components need to have visible anywhere for us to
‫be able to adjust their parameters in the details panel.
‫Now, I'm not seeing any immediate need for exposure to the event graph, so I don't think we need blueprint
‫read, write or blueprint read only.
‫That's okay.
‫If you added them, I'm going to leave them out now.
‫I'm going to give these a category.
‫And since these are components, I'm going to just stick them in our components category along with
‫our other components.
‫Now I'm not exposing these to the event graph, so I don't need our meta allow private access specified
‫here.
‫So this is enough for spring arm and I'd like to give the camera component the same you property.
‫So I'm copying it over.
‫So now we have our components.
‫The next thing to do is to construct them in the constructor, which means we need a constructor.
‫Now the constructor will be the same name as the class, so it's a tank and we need to define this constructor
‫in the CP file.
‫So let's go to Tank CP and create a tank.
‫So there's our function body and the tank constructor must be prefixed with our class name and the scope
‫resolution operator.
‫That's these double colons here.
‫That way we're not just creating a new function, but defining our constructor for this class.
‫Now we'd like to construct these components.
‫So let's start with the spring arm.
‫So we're going to say spring arm equals create default sub object and this will be a u spring arm component.
‫And for the text, I'll simply call this spring arm.
‫And for the attachment, we're going to set spring arm, set up attachment, passing in root component.
‫Now.
‫I was waiting for it.
‫There it is.
‫The IntelliSense error saying pointer to incomplete class type use spring arm component.
‫That's because we need to include the header file since we're creating and using a spring arm component.
‫So here's my unreal engine documentation and if I scroll down, there's my include.
‫So I'm going to copy that and paste it right here at the top, just under tank edge.
‫Now, just a side note in general, you're going to keep your class header file included at the top
‫and includes for your components underneath that.
‫So we have our spring arm.
‫It's time to construct the camera.
‫So we're going to say camera create default sub object, you camera component.
‫And in the text macro, I'm going to call this simply camera.
‫And for the camera I'm going to call setup attachment passing in spring arm.
‫And of course I need the camera header file.
‫So here's the unreal engine documentation and here where it says search documentation, I'm going to
‫type you camera component and here I see you camera component.
‫I'll select that.
‫And here's the documentation for camera component.
‫So I'll copy it to include paste it right here at the top of our file.
‫And now we should be good.
‫Okay, so let's go ahead and compile this.
‫Okay.
‫So I have a successful compile.
‫Let's head back in the editor and here on -- Tank.
‫Of course, we don't see anything because -- tank is derived from base -- and the components we
‫just added, we added to the tank class.
‫So BP -- tank is not going to get those because it's not derived from the tank class.
‫Now we could go and create a new blueprint based on the tank class, but then we'd have to set up these
‫components all over again.
‫And I don't really feel like going through all that work a second time.
‫There's an easier way we can repair this blueprint to the tank class.
‫We do that by going up to class settings and in the details panel with class settings selected, we
‫see class options and there's this parent class.
‫The dropdown shows that it's set to base upon, but if we click on it, we can search for tank and choose
‫tank as the base class.
‫And now this blueprint is derived from the tank class.
‫So we see that all of those properties we set with our components such as the mesh and the capsule size,
‫they're all still there.
‫Only now we see a camera.
‫In fact, we have a spring arm and a camera.
‫And if we select the spring arm now, we can see that red line.
‫So this is great.
‫So I could take this spring arm component and change its target arm length.
‫If I like, I could set it to something like 600 and I can even change its rotation so that it's angling
‫the camera down at the tank by selecting rotation mode and rotating it up a bit.
‫Like So now I'd like to point out that you shouldn't change the camera's location.
‫It might be tempting to select the camera and move it around in the world so that you position it and
‫angle it just right.
‫But this is not the correct way to do it.
‫The correct way is to set the rotation and target arm length of the spring arm component.
‫And the reason is you want that camera attached to the end of the spring arm.
‫The spring arm has lots of different built in features such as shrinking in when the camera hits up
‫against a wall to avoid obstacles, blocking the view to the pond and other things like that.
‫So you're going to want that camera attached to the end of the spring arm and then adjust the spring
‫arm rather than adjusting the camera's position and rotation.
‫So in this video we created the tank class and we derived from base pond to inherit those qualities
‫from the base pond class.
‫We added a spring arm component and a camera component and exposed those to the editor using visible
‫only and put them in their own category.
‫So we're getting closer to the finished product step by step, and we'll continue developing this tank
‫in the next lecture.
‫I'll see you soon.