In this lesson, you will learn how to organize your C++ code into distinct modules using Unreal’s build configuration files.
Why Use Modules?
As your project grows, putting all your code into one giant folder becomes messy and slows down compilation. Unreal Engine solves this by using Modules. A module is a collection of C++ source code that is compiled as a single unit. Think of them as "building blocks" for your game. If you have a core gameplay system and a separate UI system, you can keep them in different modules so that changing one doesn't force the entire project to recompile.
The Build File (.Build.cs)
Every module has a corresponding C# file ending in .Build.cs (e.g., MyProject.Build.cs). This file tells the Unreal Build Tool how to handle your code. It lives in your module's Source directory.
When you open this file, you will see a constructor that looks something like this:
public class MyProject : ModuleRules
{
public MyProject(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
// Dependencies go here
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
}
}
Configuring Dependencies
The most important part of this file is the PublicDependencyModuleNames list. If your module needs to talk to other parts of the engine—like the UI system (UMG) or the enhanced input system—you must add them to this list. If you don't list a module here, your code won't be able to "see" or use the classes inside those modules, and you will get compilation errors.
By defining these relationships, you create a clear map for the compiler. This keeps your project lightweight and ensures the engine only loads the code it actually needs to run your specific features. As you add new engine features to your project, you will regularly return to this file to update these dependencies.
Key Takeaway: Build configuration files (.Build.cs) act as the gatekeepers for your C++ modules, allowing you to organize code into manageable chunks and explicitly define which engine systems your project relies on.