Implementing the Actor functionality by composition

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.

Getting ready

This recipe will use the Actor class created in the Creating a custom Actor in C++ recipe.

How to do it...

  1. Add a new member to your custom class in C++ by making the following changes in the public section:
    UPROPERTY()
    UStaticMeshComponent* Mesh;
  2. Add the following line to the constructor ...

Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.