# How to compile in non-unity mode?

**URL:** <https://forums.unrealengine.com/t/how-to-compile-in-non-unity-mode/94863>\
**Category:** C++\
**Tags:** unreal-engine, Engine-Source-Code, GitHub, Engine-Source-GitHub\
**Created:** [June 21, 2017, 5:35am UTC](https://forums.unrealengine.com/t/how-to-compile-in-non-unity-mode/94863 "2017-06-21T05:35:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![wilberolive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@wilberolive](https://forums.unrealengine.com/u/wilberolive)\
**Post date:** [June 21, 2017, 5:35am UTC](https://forums.unrealengine.com/t/how-to-compile-in-non-unity-mode/94863/1 "2017-06-21T05:35:57Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![Frozenfire](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Frozenfire](https://forums.unrealengine.com/u/Frozenfire)\
**Post date:** [July 3, 2017, 10:10am UTC](https://forums.unrealengine.com/t/how-to-compile-in-non-unity-mode/94863/2 "2017-07-03T10:10:15Z")

</div>

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?”

---

<div class="post-metadata">

**Author:** ![huwp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@huwp](https://forums.unrealengine.com/u/huwp)\
**Post date:** [August 20, 2017, 2:00am UTC](https://forums.unrealengine.com/t/how-to-compile-in-non-unity-mode/94863/3 "2017-08-20T02:00:54Z")

</div>

The build flags are bUseUnityBuild and bUsePCHFiles.

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

```auto

<?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:

```auto

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

		bUseUnityBuild = false;
		bUsePCHFiles = false;
...

```

---

<div class="post-metadata">

**Author:** ![gmpreussner](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gmpreussner/32/903591_2.png) [@gmpreussner](https://forums.unrealengine.com/u/gmpreussner)\
**Post date:** [August 22, 2017, 7:45pm UTC](https://forums.unrealengine.com/t/how-to-compile-in-non-unity-mode/94863/4 "2017-08-22T19:45:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gmpreussner](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gmpreussner/32/903591_2.png) [@gmpreussner](https://forums.unrealengine.com/u/gmpreussner)\
**Post date:** [August 31, 2017, 10:40pm UTC](https://forums.unrealengine.com/t/how-to-compile-in-non-unity-mode/94863/5 "2017-08-31T22:40:12Z")

</div>

\> 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 ;)).

---

<div class="post-metadata">

**Author:** ![teak421](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/teak421/32/902996_2.png) [@teak421](https://forums.unrealengine.com/u/teak421)\
**Post date:** [August 31, 2017, 11:32pm UTC](https://forums.unrealengine.com/t/how-to-compile-in-non-unity-mode/94863/6 "2017-08-31T23:32:09Z")

</div>

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

teak

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_32cf160f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_32cf160f](https://forums.unrealengine.com/u/anonymous_user_32cf160f)\
**Post date:** [September 10, 2017, 4:47am UTC](https://forums.unrealengine.com/t/how-to-compile-in-non-unity-mode/94863/7 "2017-09-10T04:47:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_342c85a4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_342c85a4](https://forums.unrealengine.com/u/anonymous_user_342c85a4)\
**Post date:** [December 26, 2017, 7:37pm UTC](https://forums.unrealengine.com/t/how-to-compile-in-non-unity-mode/94863/8 "2017-12-26T19:37:39Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![shdwjk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shdwjk/32/1049049_2.png) [@shdwjk](https://forums.unrealengine.com/u/shdwjk)\
**Post date:** [March 3, 2020, 7:04pm UTC](https://forums.unrealengine.com/t/how-to-compile-in-non-unity-mode/94863/9 "2020-03-03T19:04:38Z")

</div>

> [@anonymous\_user\_342c85a4](#):
>
> 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](https://docs.unrealengine.com/en-US/Programming/Development/VisualStudioSetup/UnrealVS/index.html)):

> [@](#):
>
> Iterating on a Single Source File  
> If you’re used to iterating on updates to a single source (.cpp) file using [Ctrl+F7](https://docs.microsoft.com/en-us/visualstudio/ide/default-keyboard-shortcuts-for-frequently-used-commands-in-visual-studio) in Visual Studio, you can bind **Ctrl+F7** to the **UnrealVS.CompileSingleFile** command, which builds your active project with the current solution configuration, platform, and the -singlefile=\<Path to currently open file\> argument.
