How to compile in non-unity mode?

So I’m in the process of converting the source of my project over to the IWYU model. I’m following this guide.

https://docs.unrealengine.com/latest/INT/Programming/UnrealBuildSystem/IWYUReferenceGuide/index.html

The first thing I did was remove the #include of my <project name>.h file from the top of all my headers files. This effectively removed the “Engine.h” from my project. I then tried compiling and to my shock and horror it compiled just fine without a single error. This may sound like a great success, however the scary thing about it now is that I’m not including any UE4 headers anywhere in my project… at all… anywhere… nothing… zero!

I’ve tried doing a full rebuild… I’ve tried regenerating the project files… I’ve scoured through my source files looking for stray UE4 header includes… nothing! I have no idea how I can add a custom MyActor.h and MyActor.cpp file to my project and write code that uses UE4 with no included headers at all and it compiles and runs.

Anyway, at the bottom of the above linked article, it has the following line.

To verify that all of your source files include all of their required dependencies, compile your game project in non-unity mode with PCH files disabled.

So my questions is, how do I compile my game project in non-unity mode with PCH files disabled? What is non-unity mode and how do I turn it on and how exactly do I disable PCH files?

3 Likes

I’m wondering about this as well

“What is non-unity mode and how do I turn it on and how exactly do I disable PCH files?”

The build flags are bUseUnityBuild and bUsePCHFiles.

They can be set either in “%AppData%\Unreal Engine\UnrealBuildTool\BuildConfiguration.xml” like this:



<?xml version="1.0" encoding="utf-8" ?><Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
	<BuildConfiguration>
		<bUseUnityBuild>false</bUseUnityBuild>
		<bUsePCHFiles>false</bUsePCHFiles>
	</BuildConfiguration>
</Configuration>

Or in your project’s Target files MyProject.Target.cs and MyProjectEditor.Target.cs, like this:



public class MyProjectTarget : TargetRules
{
	public MyProjectTarget(TargetInfo Target) : base(Target)
	{
		Type = TargetType.Game;

		bUseUnityBuild = false;
		bUsePCHFiles = false;
...

6 Likes

FWIW on Windows 10, I have my BuildConfiguration.xml in *c:\Users[UserName]\AppData\Roaming\Unreal Engine\UnrealBuildTool*

> What is non-unity mode

By default, UBT will combine several .cpp files into a single one. This reduces compile times when building the whole Engine as less files and include headers need to be processed. This is called a ‘unity’ build.

The downside is that, by gobbling several files together, it is easy to mask missing include dependencies. Even though you might have forgotten to include a required header or forward declaration, if the right files get combined in just the right order, everything will still work. However, as your code base evolves, it can happen that suddenly different files are getting combined. You might have just added one line of code in one file, and suddenly something else in a completely unrelated file module fails to compile.

Non-unity compilation means that UBT will not combine any files and process every compilation unit separately, like most compilers and IDEs do.

I have not measured if there is any performance difference when modifying only a few times at a time. Personally, I always use non-unity builds, because I work on many systems and platforms in parallel, and I need to ensure that everything compiles everywhere and under all circumstances. Almost all other developers at Epic Games use unity builds, however (much to my frustration, because I constantly have to fix their missing include statements and forward declarations ;)).

17 Likes

Learn something new just by roaming the forums, thanks Max.

teak

I’m new to Unreal. Good to know that the engine is evolving. Learned something new today about the engine’s internal working :slight_smile:

I did that and it doesnt work. I still cant compile individual files in Visual Studio… and also files are built together…
I know that because I created a dummy file that has an #include <windows.h> which will conflict with core files. What I want to do is I want to debug the hot reloading… and this is the only way I can come of to stop the constructor and attach to the editor at the right time…
If you have a better idea how can I debug if hot reloading works Im all ears…

This topic is about causing files to be individually compiled as part of the full build process. What you want can be done with the UnrealVS Extension (Using the UnrealVS Extension for Unreal Engine C++ Projects | Unreal Engine 5.3 Documentation):

1 Like