In this lesson, you will learn how the Unreal Header Tool (UHT) creates the "metadata" necessary for the engine to understand your C++ code at runtime.
The Problem: C++ is a "Black Box"
Standard C++ is a static language. Once you compile your code into machine instructions, the original variable names, class structures, and properties essentially disappear from the program's perspective. However, Unreal Engine needs to "see" your code to handle things like automatic garbage collection, serializing data to disk, or exposing variables to the Editor’s Details Panel.
Because C++ doesn't provide this "Reflection" natively, Unreal creates its own.
How UHT Builds the Bridge
When you compile your project, the Unreal Header Tool (UHT) runs before the compiler. It scans your header files for special macros like UCLASS(), UPROPERTY(), and UFUNCTION().
Think of UHT as a librarian who reads your code before it is packed into a crate. It takes notes on every variable and function you’ve marked with a macro and generates a "manifest" (a hidden, auto-generated .generated.h file).
Consider this snippet:
UCLASS()
class AMyActor : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
float Health;
};
When UHT sees UPROPERTY(), it logs the existence of Health into a metadata database. During runtime, the engine looks at this database to see that Health exists as a float. Because of this, the engine can automatically:
- Serialize: Save the value of
Healthto a.uassetfile. - Inspect: Draw an input field for
Healthin the Editor Details panel. - Manage Memory: Track if
Healthis being used by another object.
Without UHT, the engine would see your float Health simply as a raw memory address, having no idea that it represents a gameplay value that needs to be saved or edited. The Reflection System is effectively the "interpreter" that bridges the gap between raw C++ code and the interactive, user-friendly nature of the Unreal Editor.
Key Takeaway: The Unreal Header Tool acts as a pre-compiler that generates metadata, allowing the engine to inspect and manipulate your C++ objects while the game is running.