Unreal always fully recompiles

Hi,

I’m modifying UE and the modification itself works. However, VS keeps triggering full rebuild which takes super long to finish.

Here’s the first N lines of the log:

1>Using bundled DotNet SDK version: 6.0.302
1>Running UnrealBuildTool: dotnet "..\..\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll" -Target="UnrealEditor Win64 Development" -Target="ShaderCompileWorker Win64 Development -Quiet" -WaitMutex -FromMsBuild
1>Log file: D:\code\UnrealEngine\Engine\Programs\UnrealBuildTool\Log.txt
1>Using 'git status' to determine working set for adaptive non-unity build (D:\code\UnrealEngine).
1>Waiting for 'git status' command to complete
1>Building UnrealEditor and ShaderCompileWorker...
1>Using Visual Studio 2019 14.29.30145 toolchain (C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133) and Windows 10.0.19041.0 SDK (C:\Program Files (x86)\Windows Kits\10).
1>[Adaptive Build] Excluded from Engine unity file: LightComponent.cpp
1>Determining max actions to execute in parallel (24 physical cores, 48 logical cores)
1>  Executing up to 24 processes, one per physical core
1>Building 3532 actions with 24 processes...
1>[1/3532] Compile Module.DisplayClusterTests.cpp
1>[2/3532] Link UnrealEditor-DisplayClusterTests.lib
1>   Creating library ..\Plugins\Runtime\nDisplay\Intermediate\Build\Win64\UnrealEditor\Development\DisplayClusterTests\UnrealEditor-DisplayClusterTests.lib and object ..\Plugins\Runtime\nDisplay\Intermediate\Build\Win64\UnrealEditor\Development\DisplayClusterTests\UnrealEditor-DisplayClusterTests.exp
1>[3/3532] Compile PCH.Engine.cpp
1>[4/3532] Compile SharedPCH.UnrealEd.NonOptimized.ShadowErrors.cpp
1>[5/3532] Compile SharedPCH.UnrealEd.ShadowErrors.cpp
1>[6/3532] Compile SharedPCH.UnrealEd.RTTI.ShadowErrors.cpp
1>[7/3532] Compile SharedPCH.Engine.ShadowErrors.cpp
1>[8/3532] Compile SharedPCH.Engine.RTTI.ShadowErrors.cpp
1>[9/3532] Compile PCH.UnrealEd.cpp
1>[10/3532] Compile Module.Launch.cpp
1>[11/3532] Compile Module.Engine.40_of_94.cpp
1>[12/3532] Compile Module.Engine.58_of_94.cpp
1>[13/3532] Compile Module.Engine.36_of_94.cpp
1>[14/3532] Compile Module.Engine.91_of_94.cpp
1>[15/3532] Compile Module.Engine.47_of_94.cpp
1>[16/3532] Compile Module.Engine.50_of_94.cpp
1>[17/3532] Compile Module.Engine.61_of_94.cpp
1>[18/3532] Compile Module.ResonanceAudio.cpp
1>[19/3532] Compile Module.Engine.38_of_94.cpp
1>[20/3532] Compile Module.Engine.69_of_94.cpp
1>[21/3532] Compile Module.Engine.55_of_94.cpp
1>[22/3532] Compile Module.Engine.59_of_94.cpp
1>[23/3532] Compile Module.Engine.84_of_94.cpp
1>[24/3532] Compile Module.Engine.52_of_94.cpp
1>[25/3532] Compile Module.Engine.93_of_94.cpp
1>[26/3532] Compile Module.Engine.88_of_94.cpp
1>[27/3532] Compile Module.Engine.60_of_94.cpp
1>[28/3532] Compile Module.Engine.87_of_94.cpp
1>[29/3532] Compile Module.Engine.39_of_94.cpp
1>[30/3532] Compile Module.Engine.48_of_94.cpp
1>[31/3532] Compile Module.Engine.54_of_94.cpp
1>[32/3532] Compile Module.Engine.94_of_94.cpp
1>[33/3532] Compile Module.Engine.41_of_94.cpp
1>[34/3532] Compile Module.Engine.43_of_94.cpp
1>[35/3532] Compile Module.Engine.49_of_94.cpp
1>[36/3532] Compile Module.Engine.83_of_94.cpp
1>[37/3532] Compile Module.Engine.90_of_94.cpp
1>[38/3532] Compile Module.Engine.44_of_94.cpp
1>[39/3532] Compile Module.Engine.51_of_94.cpp

The files I changed is “LightComponent.cpp” and “LightComponent.h”. As I understand it, that is not supposed to affect the entire engine.

Anyone has clues? Thanks.

1 Like

I cannot understand. It’s triggered even with only .cpp editing .

1 Like

For me Long Compilation Time Was Usually Caused by redundant Header Files So Check your Header Files in Code, including some header files will increase compilation time significantly.

1 Like

But I didn’t change the dependencies. I didn’t add any extra header files, not at all :frowning:

1 Like

Every Time You hit the Build Button, the Entire Solution Will Compile, And all Engine Classes Are in your Solution File, in UE5 I think they have developed new features that unchanged Code in Solution won’t Compile Again So The Compilation process will take less time if you have high-end PC And this still Is Happening, By Deleting “Intermediate” Folder in your project and Generating Visual Studio project files Again Your Problem May solve.

1 Like

I have met the same problem. I have two projects A and B. At least one project needs to compile the full engine.
If I compile A with the source engine for a long time, then:

  1. Compile A again with small changes, the time won’t be too long.
  2. Compile B for a long time since it compiles the whole engine again.
  3. Compile A need to take a long time again.

It seems like that A and B use different engine, each time I compile one project, I need to compile the whole engine.

1 Like

hi , have you found the solution?? ,i meet same issue. :face_with_spiral_eyes:

Not yet. The issue still exists. That is really inconvenient.

Maybe some build scripts (or somewhere ) execute commands like “make clean” leading to clean all the intermid files…

This is what ChatGPT 4o said see if its useful and let us know:

The issue you’re experiencing, where a full rebuild is triggered even though you’ve only modified a specific file (in this case, LightComponent.cpp and LightComponent.h), can be caused by several factors related to Unreal Engine’s build system, the handling of dependencies, and how Visual Studio is configured. Let’s break down potential reasons and solutions:

1. Unity Build System and Adaptive Build

Unreal Engine uses a Unity Build system, which compiles multiple source files together to speed up compilation. However, for certain files (like LightComponent.cpp in your case), the Adaptive Build system can exclude them from Unity builds, which might be causing extra files to recompile.

Solution:

  • You can try forcing the file back into Unity build by disabling the Adaptive Unity build feature. Add the following to your project’s *.uproject file or in the Build.cs file for your module:

cpp

Copy code

bUseUnityBuild = false;

This forces the engine to compile only the necessary files, but could lead to longer compile times for smaller changes.

2. Header File Dependencies

Changes to header files (LightComponent.h) can potentially cause more extensive rebuilds than changes to source files, especially if many files include this header either directly or indirectly. When a header file is modified, Unreal Build Tool (UBT) often needs to recompile all files that include it to ensure everything is up to date.

Solution:

  • Minimize the number of files that include your header. If possible, try to forward-declare classes and only include the header where absolutely necessary.
  • Use Precompiled Header (PCH) files to reduce the dependency chain.

3. Dependency Chain in Unreal Build Tool (UBT)

Unreal Build Tool uses git status (or p4 status for Perforce) to determine which files have changed and whether a full rebuild is needed. If UBT detects that your change could affect a significant portion of the engine, it will trigger a full rebuild. This could happen if:

  • There is a deeper dependency or coupling between LightComponent.h and other engine modules.
  • UBT believes your modification affects widely-used functionality in the engine.

Solution:

  • Check if LightComponent.h is indirectly included in many places. If possible, refactor or reduce its exposure in other parts of the engine.
  • Investigate Unreal Engine’s dependency cache and ensure it’s not stale. Running a full rebuild once and then subsequent incremental builds may help.

4. Outdated Intermediate or Derived Data

Sometimes, build artifacts or intermediate files from previous builds can confuse UBT or cause it to think more files have changed than they actually have.

Solution:

  • Try cleaning your build folder. You can do this by deleting the Binaries, Intermediate, and DerivedDataCache folders in your project directory. Then, rebuild the project. After this, subsequent builds should be incremental.
  • Use the “Clean Solution” option in Visual Studio before building again.

5. Visual Studio Configuration

If your Visual Studio solution is not correctly configured or if there are leftover files from older configurations, it might trigger unnecessary rebuilds.

Solution:

  • Ensure that you’re using the correct build configuration (e.g., Development Editor).
  • Go to Project PropertiesConfiguration PropertiesC/C++Code Generation, and make sure the Runtime Library setting is consistent across your entire solution (i.e., use /MD or /MDd but not a mix).
  • Check for any old or incorrect project files in your solution that could be triggering additional rebuilds.

6. Build Logs

The build log you provided shows that the process starts by excluding LightComponent.cpp from the Unity build. If you observe which modules or files are being compiled as a result of this exclusion, it may help pinpoint where the chain of rebuilds is stemming from. You can also enable more verbose logging by adding:

sh

Copy code

-Verbose

to your Unreal Build Tool command line, and then analyze which dependencies are triggering the rebuild.


Summary of Actions:

  1. Temporarily disable adaptive Unity build to see if that helps.
  2. Minimize the scope of LightComponent.h by forward-declaring or reducing includes.
  3. Clear build artifacts by cleaning the Intermediate, Binaries, and DerivedDataCache folders.
  4. Check Visual Studio settings for mismatches in configuration.
  5. Use verbose logging to trace the full dependency chain.

By systematically addressing these factors, you should be able to resolve the issue or at least significantly reduce the scope of the rebuilds.