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

Analyzing Generated Header File Structures

You will examine the contents of generated .generated.h files to understand how UHT injects boilerplate code into your C++ class declarations.

In this lesson, you will learn how to peek behind the curtain of the Unreal Header Tool (UHT) by examining the boilerplate code generated within your class's .generated.h files.

Why do these files exist?

When you define a class with the UCLASS() macro, C++ alone cannot handle the complex requirements of Unreal’s reflection system (like garbage collection, serialization, and Blueprint integration). During compilation, UHT parses your header and writes a corresponding .generated.h file. This file contains the "glue" code that allows the engine to understand your class structure.

What is actually inside?

If you open your MyCharacter.generated.h file (found in your project’s Intermediate/Build folder), you will see several blocks of generated macros. The most important ones you’ll encounter are:

  1. DECLARE_CLASS: This block provides the engine with the metadata it needs to instantiate your class and link it to the Unreal Object system.
  2. DECLARE_SERIALIZER: This code enables your class to be saved to and loaded from disk (Serialization).
  3. _INLINE definitions: UHT generates a series of helper functions and macros that bridge your custom C++ logic to the engine's internal UClass representation.

A Peek at the Structure

The file typically looks like a series of macro chains. For example, you might see something like this:

#define MyProject_Source_MyCharacter_h_12_RPC_WRAPPERS \
    DECLARE_FUNCTION(execMyFunction);

This RPC_WRAPPERS macro is specifically designed for your UFUNCTION() declarations. It tells the engine how to call your C++ function when triggered by a Blueprint or a network event. Without this code, the engine wouldn't know how to pass arguments from the Blueprint graph into your C++ function variables.

How to analyze it

You should never modify these files, as they are overwritten every time you compile. However, if you ever receive a cryptic compilation error—such as a missing definition for a UFUNCTION or a class type mismatch—the .generated.h file is where you can look to see if the engine correctly recognized your declarations. If your function doesn't appear in the _RPC_WRAPPERS section, you know UHT missed your macro.

Key Takeaway: The .generated.h file is the bridge between your high-level C++ code and the engine's core architecture, automatically creating the boilerplate necessary for reflection, serialization, and Blueprint communication.