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

Utilizing the Unreal Header Tool Macros

Learners will apply reflection macros to C++ classes and variables, enabling the engine to track and interact with their code.

In this lesson, you will learn how to use reflection macros to grant Unreal Engine the ability to "see" and interact with your C++ classes and variables.

Why Do We Need Macros?

By default, C++ is a "compiled" language that the engine cannot easily inspect while the game is running. Unreal Engine solves this with a system called Reflection. To enable this, the Unreal Header Tool (UHT) scans your code before it compiles. UHT looks for specific "magic words" (macros) that tell the engine: "Hey, keep track of this class so I can use it in the Editor."

The Two Essential Macros

To make a C++ class visible to the engine, you must use two specific macros inside your header (.h) file:

  1. UCLASS(): Placed directly above your class declaration. This tells UHT that this class is an Unreal object.
  2. GENERATED_BODY(): Placed inside the class, right at the top. This acts as a placeholder where UHT injects all the necessary background code to make your class work with the Unreal Editor.

Here is how a standard class header looks:

UCLASS()
class MYPROJECT_API AMyActor : public AActor
{
    GENERATED_BODY()

public:
    UPROPERTY(EditAnywhere)
    float MovementSpeed;
};

Exposing Variables

Notice the UPROPERTY() macro above the MovementSpeed variable. Just as UCLASS() tells the engine about your class, UPROPERTY() tells the engine to track that specific variable. By adding (EditAnywhere) inside the parentheses, you are explicitly telling Unreal: "Let me edit this value in the Details panel inside the Editor."

Without these macros, the engine would treat your class like a standard, invisible C++ object, meaning you wouldn’t be able to spawn it in your levels or see its properties in the UI.

Key Takeaway: Macros act as markers that allow the Unreal Header Tool to bridge the gap between your raw C++ code and the visual Unreal Editor interface.