Course contentsShow
← Unreal Engine Game Development
Lesson 29 of 8801. Foundations and Editor WorkflowFree lesson

Implementing UCLASS Macros for Type Discovery

Declare classes using the UCLASS macro to register them with the reflection system for engine-level tracking and blueprint compatibility.

In this lesson, you will learn how to use the UCLASS macro to register your C++ code with Unreal’s reflection system so the Editor can "see" and utilize your classes.

The Problem of Visibility

In standard C++, the compiler converts your code into machine instructions that the computer understands. However, the Unreal Editor—which lets you drag-and-drop objects, edit variables, and create Blueprints—needs more than just raw machine code. It needs metadata. Without help, the Editor wouldn't know your class exists, what properties it has, or how it should behave in a level.

Entering the UCLASS Macro

The UCLASS macro acts as a bridge between your C++ code and the Unreal reflection system. When you place this macro above your class declaration, the Unreal Header Tool (UHT) parses your header file during compilation. It generates the necessary "glue" code that allows the engine to track your class, store its properties, and expose it to the Editor’s menus.

Think of the UCLASS macro as a "registration form." By filling it out, you are telling the engine: "Please track this class, allow me to spawn it in the world, and make it available for Blueprints."

Implementation Example

To register a class, you place the macro directly above your class keyword. You must also include the GENERATED_BODY() macro inside the class to complete the registration process.

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyCustomActor.generated.h" // Required: The header UHT creates

UCLASS() // This macro enables reflection for this class
class MYPROJECT_API AMyCustomActor : public AActor
{
    GENERATED_BODY() // This macro handles the generated bookkeeping code

public:
    AMyCustomActor();
};

Without the UCLASS() macro, your class will compile, but it will be invisible to the Editor. You wouldn't be able to create Blueprints based on it, nor would you see it in the Content Browser. By adding this macro, you provide the engine with the metadata required to bridge the gap between your C++ logic and the visual design environment.

Key Takeaway: The UCLASS macro is your essential registration tag that allows the Unreal reflection system to track your class and expose it to the Editor’s visual tools.