Course contentsShow
← Unreal Engine Game Development
Lesson 220 of 8803. C++ and UObject ArchitectureFree lesson

Configuring Class Behavior with UCLASS Metadata

Students will apply class specifiers to define inheritance, Blueprint compatibility, and editor-specific behaviors to optimize the instantiation of custom actor types.

In this lesson, you will learn how to use UCLASS specifiers to control how your C++ classes interact with the Unreal Editor and Blueprint systems.

Controlling Class Behavior

While the UCLASS() macro identifies a class to the Unreal reflection system, the specifiers inside its parentheses act as a set of instructions for the engine. By configuring these, you define whether a class can be placed in a level, whether it should appear in the "Create Blueprint" menu, or if it should be hidden from specific editor tools.

For example, if you are building a base class that holds logic but should never exist as an actual object in your game, you use the Abstract specifier. Conversely, if you want your C++ class to be easily extendable by designers, you use Blueprintable.

Practical Implementation

Consider a base class for a specialized pickup system. You want designers to create variations of this in the Editor, but you want to prevent them from accidentally spawning the base class itself:

UCLASS(Blueprintable, Abstract, meta = (BlueprintSpawnableComponent))
class AMyBasePickup : public AActor
{
    GENERATED_BODY()
    // ...
};

Here is what these specifiers tell the engine:

  • Blueprintable: Allows designers to create Blueprint classes that inherit from this C++ class.
  • Abstract: Prevents this class from being placed in the level or spawned during gameplay. It marks this class as a "template" only.
  • meta = (BlueprintSpawnableComponent): If this were a component, this would allow it to be added to any Actor Blueprint via the "Add Component" button.

Why this matters

Metadata provides the "user manual" for the Unreal Editor. By strictly configuring your UCLASS specifiers, you prevent bugs where designers might instantiate the wrong base classes or clutter the content browser with unnecessary options. You aren't just writing code; you are building a toolset for your team that enforces architecture through the Editor’s interface.

Key Takeaway: UCLASS specifiers act as architectural constraints that define how your C++ classes are exposed, instantiated, and managed within the Unreal Editor environment.