‫Welcome back.
‫So we've already created a new capsule component pointer and forward declared it so we didn't have to
‫include the header file in base upon h.
‫It's now time to actually construct a capsule component sub object for our base POM And once we do that,
‫we're going to set our root component to be the capsule.
‫So how do we actually construct a you capsule component?
‫The process is very unreal.
‫Engine specific unreal engine has create default sub object.
‫This is a template function.
‫A template function adapts to the type chosen so we can choose a particular type and create default.
‫Sub object will adapt to that type.
‫We pass in the type that we wish to construct into create default sub object.
‫Unlike a regular function, it has these angle brackets.
‫This is where we pass in the type to construct.
‫Now create default sub object also takes an argument in its parentheses.
‫This is going to be a name that we assign to the sub object.
‫This is different than the variable name and it's passed in as a string literal.
‫So here's an example.
‫Let's say we wish to create a u static mesh component.
‫So we call create default sub object and end the angle brackets we pass in the type u static mesh component
‫and in the parentheses we give it a name.
‫Now you've already seen that for String Literals, you should use the text macro.
‫So we're passing our string literal in using the text macro here.
‫Now, as I mentioned, this is an internal name used by Unreal Engine.
‫There are other functions that use this.
‫For example, there's a function called get default sub object by name.
‫It retrieves a sub object belonging to a particular object and you can call it passing in a particular
‫name and it'll look for the sub object with that chosen name.
‫So the overall function call to create default sub object looks like this.
‫The type goes in the angle brackets and the name goes in the parentheses.
‫Now create default sub object returns the address of the newly created component.
‫So in our case, if we passed in use static mesh component as the type, then we get the address of
‫a use static mesh component and we can store that in a pointer since pointers store addresses of things.
‫So say we create a use static mesh component pointer called mesh.
‫Then we can take that address returned by create default sub object and store that address in our mesh
‫pointer.
‫So now that you know how create default sub object works, you're going to use this to construct a capsule
‫component object.
‫You're going to do this in the base PON constructor use create default sub object to construct a capsule
‫component pass in you capsule component and the angle brackets as the type to construct and pass in
‫capsule collider wrapped in a text macro in the parentheses.
‫Pause the video and add this to base pont CP in the constructor now.
‫Okay.
‫So we're here in Bass Pond.
‫CP and we'd like to construct a capsule component.
‫So we're going to take our capsule comp variable and assign the value returned by create default sub
‫object.
‫Now, as we've seen, this template function has angle brackets as well as parentheses, and we saw
‫that the type goes in the angle brackets, we're going to use U capsule component.
‫And for the parentheses we're going to use the text macro and we're going to call this capsule collider.
‫And there we go.
‫Now we're using you capsule component to construct an object of this type.
‫And when we use a type, we include its header file.
‫Now let's see what happens when we attempt to compile.
‫Now again, you can use live coding or you can compile here in VZ code.
‫I'm going to be compiling here in VTS code throughout this section.
‫So you can just know that when I compile I have closed the Unreal Engine editor and I'm just compiling
‫from here.
‫I'd like to see the error message here and VTS code now attempting to compile this here.
‫We get a different error than the one we saw in the last video.
‫Use of undefined type u capsule component.
‫This time we're trying to use the U capsule component type here in the CPP file to construct an object.
‫Here's the error code in case you wish to Google this particular type of error for more information.
‫So now we've seen two different types of compilation errors in this section of the course, and we know
‫the cause of this particular error.
‫We haven't included you capsule component.
‫Now here's U capsule component in Unreal Engine's documentation and here's the include that we need
‫for this type.
‫So I'm going to copy this and paste it here at the top of Base Pond CPP.
‫Now if I attempt to compile again, compilation is successful, we see no errors.
‫I'm going to close the terminal now.
‫So we've created the capsule component.
‫The next thing I'd like to do is make sure the capsule component is the root.
‫Now we saw how to assign a component as the root and blueprints by clicking and dragging in C++.
‫It's also pretty easy.
‫We simply take that root component variable and assign it the value of capsule comp.
‫Now we've specified that capsule comp should be the root component.
‫Let's compile this again.
‫And now after a successful compilation, I'd like to hop back into the editor.
‫Okay.
‫I've opened up the editor and I'm going to take my base --, C++ class and drag one in.
‫And now check this out.
‫We see a capsule component.
‫Now in the world, out liner.
‫It shows that the base -- that I just dragged in is selected now just above search in the details
‫panel.
‫I can drag this down and see all components on this base --.
‫And all we see is this capsule comp because that's the only component that it has.
‫So we've now added our capsule component and we see the result of that when we actually add an instance
‫of this class into the world in the Unreal Engine Editor.
‫So in summary, we've learned how to construct a capsule component from C++, and we made it the root
‫component by assigning the value of the root component variable to capsule comp.
‫In the next video, we're going to add more components to our base in C++ class.
‫I'll see you then.