Configuring the Unreal Header Tool Environment
In this lesson, you will learn how to configure your project’s build files to ensure the Unreal Header Tool (UHT) can correctly identify and parse your custom C++ classes for the reflection system.
Understanding the UHT Pipeline
The Unreal Header Tool is a dedicated utility that runs before your actual C++ compiler. It scans your source code for reflection macros—like UCLASS(), UFUNCTION(), and UPROPERTY()—to generate the "glue" code necessary for the engine to track your objects. If your project is not configured correctly, UHT will skip your files, and you’ll see compilation errors stating that your classes are unrecognized or missing essential generated headers.
The Role of Build.cs
The primary configuration file for this process is your project's .Build.cs file (found in the Source/YourProjectName folder). This file tells the Unreal Build Tool (UBT) how to handle your code. For UHT to function, your module must include the correct dependencies.
To ensure your environment is set up properly, you must include the Core, CoreUObject, and Engine modules in your PublicDependencyModuleNames. This informs UHT that your module relies on the UObject architecture:
public class MyProject : ModuleRules
{
public MyProject(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] {
"Core",
"CoreUObject",
"Engine",
"InputCore"
});
}
}
Essential Formatting
Beyond the .Build.cs file, UHT enforces strict file naming conventions. Every C++ class that uses reflection must have its header file named exactly as the class it contains (e.g., MyActor.h must contain class AMyActor). Furthermore, the very last #include statement in your header file must be the generated header:
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h" // UHT requires this specific line
If the .generated.h file is missing or placed incorrectly, UHT will fail to parse the class, rendering your reflection macros invisible to the engine. By keeping your Build.cs dependencies accurate and your header structure consistent, you ensure UHT can successfully generate the code required to integrate your logic into the engine’s framework.
Key Takeaway: To enable the reflection system, verify your module dependencies in the .Build.cs file and ensure every UObject-derived header ends with the mandatory #include "ClassName.generated.h" directive.