TExcelTAD
Home › Unreal Engine 5 with C++ › Toolkit: Live Coding, UBT & UHT

Toolkit: Live Coding, UBT & UHT

Unreal doesn't use CMake or MSBuild for its C++. It has its own build system, and knowing its parts explains most build oddities: why adding a UPROPERTY needs an editor restart, why a new file needs "Refresh project files", why a one-line change rebuilt 300 files.

The pieces

Tool Written in Job
UnrealBuildTool (UBT) C# reads *.Target.cs and *.Build.cs, works out modules, include paths and defines, runs UHT, then drives the compiler and linker; also generates IDE project files
UnrealHeaderTool (UHT) C# (built into UBT since UE 5.1; it used to be a C++ program) parses reflected headers and writes .generated.h / .gen.cpp
Live Coding Live++ technology licensed by Epic patches recompiled functions into the running editor or game
UnrealAutomationTool (UAT) C# high-level jobs: packaging (BuildCookRun), BuildGraph, tests

The IDE's Build button calls UBT (Engine/Build/BatchFiles/Build.bat). You can call it yourself:

bat
Engine\Build\BatchFiles\Build.bat ArenaEditor Win64 Development -Project="D:\Projects\Arena\Arena.uproject" -WaitMutex

Generated files land in Intermediate/ and binaries in Binaries/. Deleting Intermediate/, Binaries/ (and .vs/, the .sln) and regenerating project files is the "turn it off and on again" of Unreal builds. It fixes stale-generated-code errors at the cost of a full rebuild.

Unity builds and IWYU

To speed up full builds, UBT concatenates many .cpp files into a few large unity files (Module.Arena.1.cpp). Two consequences:

  • A missing #include can go unnoticed because a neighbouring file in the same unity blob included it. The bug appears later when files get regrouped. Build with -DisableUnity (or bUseUnity = false in Build.cs temporarily) to catch these.
  • Files you're actively editing are moved out of the unity blob automatically (adaptive unity, based on your source-control writable state), so iteration stays fast.

Unreal follows Include What You Use (IWYU): each file includes the headers for what it uses, and headers forward-declare classes (class UCameraComponent;) instead of including them. Keeping headers light is the single biggest lever on compile times in a growing project.

Live Coding vs a full rebuild

Live Coding (on by default in UE5; Ctrl+Alt+F11 in the editor, or the compile button in the toolbar) recompiles changed .cpp files and patches the new function bodies into the running process. It is the fastest loop for gameplay code. Its limits follow from what it does:

Change Live Coding
change code inside a function body in a .cpp ✔ patches it
add a new non-virtual function used only in that .cpp ✔ usually
change a default value in a constructor ⚠ new objects only; existing instances and Blueprint defaults keep old values
add/remove/reorder member variables (changes class size and layout) ✘ needs restart (experimental object reinstancing in Live Coding settings handles some cases)
add or change UPROPERTY / UFUNCTION / UCLASS / USTRUCT (reflection) ✘ close the editor, build from the IDE, reopen
add a new .cpp/.h file or a new module ✘ regenerate project files, full build
change Build.cs / Target.cs ✘ full build

The safe habit: header change → close the editor → build in the IDE → reopen. Use Live Coding for everything inside function bodies.

Warning: The old Hot Reload (recompiling a module DLL while the editor runs, without Live Coding) is the cause of many "my Blueprint lost its variables" and corrupted-asset stories. In UE5 Live Coding replaces it; keep Hot Reload off, and never save Blueprints right after a hot-reload that changed reflected types.

A model: will Live Coding apply this change?

cpp · try it yourself
#include <iostream>
#include <string>
#include <vector>

struct Change { std::string What; bool InHeader, ChangesLayout, ChangesReflection, NewFile, BuildRules; };

std::string Verdict(const Change& c) {
    if (c.BuildRules || c.NewFile) return "regenerate project files + full build";
    if (c.ChangesReflection) return "close editor, build in IDE, reopen (UHT must run)";
    if (c.ChangesLayout) return "restart needed (object layout changed)";
    if (c.InHeader) return "Live Coding may work; inline code in headers rebuilds every includer";
    return "Live Coding: Ctrl+Alt+F11";
}

int main() {
    std::vector<Change> changes = {
        {"tweak damage formula in ApplyDamage()", false, false, false, false, false},
        {"add `float CritChance;` member (no UPROPERTY)", true, true, false, false, false},
        {"add UPROPERTY(EditAnywhere) CritChance", true, true, true, false, false},
        {"edit an inline getter in the header", true, false, false, false, false},
        {"add ArenaLoot.cpp/.h", true, false, true, true, false},
        {"add \"Niagara\" to Build.cs", false, false, false, false, true},
    };
    for (const auto& c : changes) std::cout << "- " << c.What << "\n    -> " << Verdict(c) << "\n";
}
- tweak damage formula in ApplyDamage()
    -> Live Coding: Ctrl+Alt+F11
- add `float CritChance;` member (no UPROPERTY)
    -> restart needed (object layout changed)
- add UPROPERTY(EditAnywhere) CritChance
    -> close editor, build in IDE, reopen (UHT must run)
- edit an inline getter in the header
    -> Live Coding may work; inline code in headers rebuilds every includer
- add ArenaLoot.cpp/.h
    -> regenerate project files + full build
- add "Niagara" to Build.cs
    -> regenerate project files + full build

Build failures you'll meet

Message Usual cause
Unable to build while Live Coding is active close the editor (or press Ctrl+Alt+F11 there instead) before building in the IDE
Cannot open include file: 'X.generated.h' UHT didn't run for that header: missing UCLASS, wrong file name, or stale Intermediate; regenerate and rebuild
unresolved external symbol for an engine class missing module in Build.cs
unresolved external symbol for your own class in another module missing ARENA_API export macro
The following modules are missing or built with a different engine version (on editor start) the editor needs your module rebuilt: click Yes, or build in the IDE to see the real error

Test yourself

You added a new UPROPERTY to a header. How do you apply it?

  1. Live Coding (Ctrl+Alt+F11)
  2. Close the editor, build in the IDE, reopen
  3. Save the Blueprint
  4. Restart Windows

What does UnrealHeaderTool do?

  1. Compiles shaders
  2. Parses reflected headers and generates the .generated.h/.gen.cpp files
  3. Packages the game
  4. Links modules

Why can a missing #include go unnoticed in an Unreal build?

  1. The compiler ignores includes
  2. Unity builds combine several .cpp files, so another file's include covers for it
  3. IWYU adds includes automatically
  4. UHT inserts them