In this lesson, you will learn how to use Target.cs files to dictate exactly what kind of executable Unreal Engine should build for your project.
What is a Build Target?
When you compile your project, Unreal doesn’t just build one "thing." It builds a Target. Think of a Target as a recipe for a specific output. You might want to build an executable for players to run the game, an executable for you (the developer) to run the Editor, or a stripped-down version for a dedicated server.
These recipes are defined in your project’s Source folder using C# files ending in .Target.cs.
Defining Your Targets
Every standard C++ project typically comes with two primary target files: YourProject.Target.cs (for the game) and YourProjectEditor.Target.cs (for the Editor).
If you look inside YourProject.Target.cs, you will see a class inheriting from TargetRules. This is where you configure the build:
public class MyGameTarget : TargetRules
{
public MyGameTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V5;
ExtraModuleNames.Add("MyGame");
}
}
Why does this matter?
- Type: Setting
Type = TargetType.Gametells the build system this is for a standalone distribution. Setting it toEditorincludes all the tools you use while making the game, which makes the file size much larger. - ExtraModuleNames: This tells the compiler which of your code modules to include. If you have a massive project, you can use these files to build specific modules while leaving others out, which speeds up your iteration time.
- Optimization: You can toggle settings like
bBuildEditor,bUseUnityBuild, orbIsClientOnlyhere to strip away unnecessary code, ensuring your final player build is as lean as possible.
By modifying these C# files, you control the "personality" of your build, ensuring you aren't compiling thousands of lines of Editor code into your final game executable.
Key Takeaway: Build Target files act as the master configuration for your project's compilation, allowing you to tailor specific executable outputs for the Editor, standalone game, or dedicated servers.