Skip to main content

.Build.cs File

All modules must have a .Build.cs file inside of the module's main folder. This is where we link our modules to other modules, forming dependencies. It also allows for more advanced configurations like setting platform-specific options, integrating third-party libraries, or controlling how the module is compiled.

Example

Your .Build.cs file will look something like this, probably with some additional sections for paths and dynamically loaded modules. I've never needed to use those so I just remove them. Here is what you need:

// Copyright Eric Buchholz. All Rights Reserved.

using UnrealBuildTool;

public class MyCustomTools : ModuleRules
{
public MyCustomTools(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
// ... add other public dependencies that you statically link with here ...
}
);

PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"Slate",
"SlateCore",
// ... add private dependencies that you statically link with here ...
}
);
}
}

Module Dependencies

When you want to use code from another module in the engine or another plugin, that module must be added to your .Build.cs file so it can be linked as a dependency. Modules that both your code and other modules interacting with your code will need should go into PublicDependencyModuleNames, and modules that are only used within your own code should go into PrivateDependencyModuleNames.

In other words...

If you're including the module in code located in your Public folder, then list it under PublicDependencyModuleNames. Modules included in code located in your Private folder should be listed under PrivateDependencyModuleNames. Generally speaking!

How do I find the name of the module?

When you include code from a different module, you need to know the name of that module so it can be included. I usually just look at the file path of the file I'm including, but you can also search for the class on the C++ API Reference site and it will tell you what to include.

Precompiled Headers (PCH)

Setting PCHUsage to UseExplicitOrSharedPCHs will improve compile times overall for your module. You can read up on the pros and cons of that if you would like, here.