Custom Actors without components don't have a location, and can't be attached to other Actors. Without a root Component, an Actor doesn't have a base transform, and so it has no location. Most Actors, therefore, require at least one Component to be useful.
We can create custom Actors through composition—adding a number of components to our Actor
, where each component provides some of the functionality required.
This recipe will use the Actor
class created in the Creating a custom Actor in C++ recipe.
Add a new member to your custom class in C++ by making the following changes in the
public
section:UPROPERTY() UStaticMeshComponent* Mesh;
Add the following line to the constructor inside the cpp file:
Mesh = CreateDefaultSubobject<UStaticMeshComponent>("BaseMeshComponent");
Verify your code looks like the following snippet, and compile it by using the Compile button in the editor, or building the project in Visual...