‫Hey, welcome back.
‫In this video, we're going to talk about components and how our base pawn is going to want some of
‫these components for things like collisions and visual representation, like meshes, as well as a spawn
‫point from which our projectiles will appear.
‫We're going to talk about how components, support, attachment so we can attach various components
‫to each other, as well as how our pawn has a root component which stores the transform information
‫for the --.
‫Now we've already created our first C++ class called Base --, and now we're ready to start adding
‫some things to the base --.
‫The base -- is going to need some components, such as meshes for the base and turret of the tank.
‫C In our meshes folder, we have a tank base, we have a tank turret and for the tower we also have
‫a base and a turret.
‫So we're going to need a couple of mesh components.
‫We're also going to want a capsule component to handle collisions so our tank and turret won't be passing
‫through each other.
‫Now, let's talk about components for a second.
‫When we add a component to a class, we need to decide what class that component should be.
‫Now, one choice is a scene component.
‫The you seen component class has some properties, such as it has a transform, meaning it has a location,
‫a rotation and such.
‫It also supports attachment.
‫This means we can attach other components to a scene component.
‫We'll learn more about how that works later.
‫And a scene component does not have a visual representation, meaning it doesn't have a mesh or anything
‫like that.
‫We can't actually see it in the game.
‫Now there are some other classes in Unreal Engine that are derived from scene component, such as a
‫capsule component.
‫The YOU capsule component class is made to handle collision and that's just about all it's good for.
‫We use the capsule component so that our -- does not fall through the floor or move through walls
‫and things like that.
‫Now also derived from the scene component class is the static mesh component.
‫The use static mesh component class gives us the ability to have a visual representation, specifically
‫a mesh that will belong to our -- class that we can see in the world as we're moving it around.
‫Now, by default, our -- class already has a component, it's called root component.
‫Let's go back into VS code and see if we can find this root component.
‫So I'm here in Base Pont CP and I'm just going to click anywhere such as here in the constructor and
‫I'm going to type root component just like that.
‫Now I'm going to right click on this and click go to definition and all of a sudden we have actor opened
‫up.
‫And here in actors in a protected section we see a you seen component pointer called root component.
‫So this variable called root component exists on the actor class.
‫So anything derived from actor will inherit this root component variable.
‫That means our base -- also has this root component variable.
‫So whenever we think about the location of a particular --, we're actually talking about the location
‫information stored in the transform of that root component, which is a scene component.
‫So scene components have their own transform.
‫I'm going to go ahead and close Actor H and delete this line that I added to the constructor of base
‫--.
‫So we know that our -- has this root component and it's type is you seen component, which means our
‫-- has a transform.
‫But we also know that this root component does not have a visual representation.
‫It's invisible.
‫However, we can reassign that root component with some other object whose type derives from seen component.
‫Now we saw that the U.
‫Capsule component class is derived from scene component.
‫So if we create a capsule, we can assign that to be the root instead of that default scene component.
‫Now we mentioned that scene components, support attachment.
‫This means we can create other components and attach them to a scene component.
‫So if we create a static mesh component, for example, called base mesh, we can attach it to the root
‫component.
‫Now, because a static mesh component is derived from the scene component class, it also supports attachment.
‫So if we create another mesh, we can attach it to the first mesh.
‫So we could create a current mesh static mesh component and attach it to the base mesh component.
‫Now we can also just create new scene components.
‫For example, if we want a scene component that we can call projectile spawn point, we can attach it
‫to the turret mesh.
‫Now why would we just create a scene?
‫Component.
‫We can't give it its own visual representation.
‫Well, if we need a spawn point, a location from which we'd like to spawn projectiles, a scene component
‫is perfect for this because it has its own transform, its own location, rotation, etc. and we can
‫use that as a point to spawn projectiles from.
‫So after assigning a capsule to be the root component, our root component will now have the U.
‫Capsule component class type and the base mesh and the turret mesh would be static mesh components and
‫our projectile spawn point would be a U seen component.
‫Now let's talk about this attachment thing for a second, because these things are all attached to each
‫other.
‫This means that as the root component moves around in space, everything that's attached to it will
‫move along with it.
‫But the base mesh itself can move relative to the root.
‫For example, it can rotate around and everything attached to the base mesh will follow along.
‫Likewise, we have this turret mesh attached to the base mesh and it itself can move independently from
‫the base mesh.
‫For example, if we rotate the turret mesh, it'll rotate and anything attached to it, such as the
‫scene component will follow along with the turret mesh.
‫So the scene component will move around along with the turret mesh as it rotates.
‫But of course if we wanted to, we could move the scene component relative to the turret mesh.
‫And since nothing is attached to the scene component, well, there's nothing to follow along with it.
‫Now let's take a look at how components work in blueprints, what the content folder selected.
‫I'm going to right click and select Blueprint Class to create a new blueprint.
‫Let's choose actor and call this Components Actor now double click components actor and notice that
‫we have default scene root.
‫This represents that root component variable we saw in C++.
‫Now, if we want, we can add new components by clicking the add button and selecting the type of component
‫we'd like to add.
‫Search for Capsule and Select Capsule Collision.
‫This is a capsule component.
‫It's C++ counterpart is the U.
‫Capsule component class.
‫Notice it's just under the default scene.
‫Root This indicates that it's attached to this scene.
‫Root We can continue adding more components.
‫For example, if you select Kub, then a static mesh component will be added and it's static mesh property
‫in the details panel will be automatically set to a cube.
‫Static mesh.
‫Now notice in the components panel, the cube is just under the capsule.
‫If we click the dropdown next to it, we no longer see the cube here so we can collapse this to hide
‫any objects that are attached to a given component.
‫Now we can reassign the root component by clicking and dragging one of our components on to the default
‫scene root.
‫For example, if I click and drag the capsule on to the default scene root, it now becomes the root
‫component.
‫So we've reassigned root component to this capsule component.
‫We can also assign attachment.
‫Let's click add and select sphere.
‫Now by default, the sphere is attached to the capsule just like the cube static mesh.
‫But if I click and drag sphere on to the cube, the sphere is now attached directly to the cube.
‫If we click the sphere and drag it on to the capsule, we have the option to either make new root or
‫attach.
‫If we select attach, the sphere will just be attached to the capsule again.
‫But if we were to select make new root, the sphere would become the root component instead.
‫So we not only have control over creation of new components and how they're attached, but we can also
‫reassign that root component.
‫Let's go ahead and select the sphere by left clicking hold shift and left click the cube to select it
‫as well and hit delete to remove these components.
‫Now for your challenge, I'd like you to become a little bit more familiar with components in blueprints.
‫Add a couple of components to our actor.
‫We already have a capsule component and that's currently the root component.
‫Add a static mesh component and for its static mesh, assign the tank base, then add a second static
‫mesh component and assign the tank turret as its static mesh.
‫Make sure to attach the base mesh to the capsule and attach the turret mesh to the base mesh.
‫Now once you've done this move and scale the base mesh and observe how the attached turret mesh behaves,
‫pause the video and give this a try.
‫Okay.
‫So I'm going to click Add and select static mesh.
‫Now in the details panel, I'm going to set the static mesh to the tank base mesh.
‫Next, I'm going to click Add and select static mesh again.
‫Notice it's automatically attached to the first static mesh because that's what I still had selected
‫in the details panel.
‫I'm going to set the static mesh to the tank turret.
‫Now with the first static mesh selected, I'm going to move it around and notice that the second static
‫mesh that's attached to it is moving along with it.
‫The same works for rotation and scale.
‫As I scale it up, the attached mesh gets bigger as well.
‫So we've talked about components and we've seen how we can attach components to other components and
‫moving and scaling.
‫One component affects the other components that are attached to it.
‫We also saw that pons inherit a root component from the actor class and this is the object that stores
‫the transform information for the pawn.
‫We'll learn about how to create components in C++ and the lectures to come.
‫I'll see you in the next video.