Command-Line Builds
If the only way to make a build is to open the editor and click Build, then only one person can make builds, they can't be reproduced, and CI is impossible. All three big engines can build headless from the command line. Automate the build in the first week of a project, while it's still small; the Field Notes explain why that pays off.
Unity: -batchmode and -executeMethod
Unity runs without a window with -batchmode, opens a project with -projectPath, calls a static C# method with -executeMethod, and quits with -quit. The method lives in an Editor folder and calls BuildPipeline.BuildPlayer:
// Assets/Editor/BuildScript.cs
using System;
using System.Linq;
using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEngine;
public static class BuildScript
{
public static void BuildWindows()
{
string version = ArgValue("-buildVersion") ?? "0.0.0-local";
PlayerSettings.bundleVersion = version;
var options = new BuildPlayerOptions
{
scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(),
locationPathName = "Builds/Windows/StarCatcher.exe",
target = BuildTarget.StandaloneWindows64,
options = BuildOptions.None,
};
BuildReport report = BuildPipeline.BuildPlayer(options);
BuildSummary summary = report.summary;
Debug.Log(quot;Build {version}: {summary.result}, {summary.totalSize} bytes, {summary.totalErrors} errors");
// A non-zero exit code makes the CI step fail.
EditorApplication.Exit(summary.result == BuildResult.Succeeded ? 0 : 1);
}
static string ArgValue(string name)
{
string[] args = Environment.GetCommandLineArgs();
int i = Array.IndexOf(args, name);
return i >= 0 && i + 1 < args.Length ? args[i + 1] : null;
}
}Run it (paths are the Unity Hub defaults; use your editor version):
# Windows (PowerShell): the call operator & runs a quoted path
& "C:\Program Files\Unity\Hub\Editor\<version>\Editor\Unity.exe" -batchmode -nographics -quit `
-projectPath . -buildTarget win64 -executeMethod BuildScript.BuildWindows `
-buildVersion 1.4.2 -logFile build.log# Linux
~/Unity/Hub/Editor/<version>/Editor/Unity -batchmode -nographics -quit \
-projectPath . -buildTarget win64 -executeMethod BuildScript.BuildWindows \
-buildVersion 1.4.2 -logFile --logFile -sends the log to standard output (handy in CI); otherwise it goes to the file you name.- Building for another OS (a Windows player on a Linux machine) needs that platform's Build Support module installed in the Hub, and the IL2CPP scripting backend generally requires building on the target OS; Mono builds cross-compile more easily.
-nographicsskips the GPU; fine for most builds, but it can't bake lighting.- Unity exits with code 1 if the method throws; calling
EditorApplication.Exit(1)reports a failed build explicitly. - Unity 6's Build Profiles can be selected with
-activeBuildProfile <path to profile asset>; Unity applies that profile's scripting defines before running your method. - Builds need a licence: a seat activated on the build machine, or a licensing server. GameCI handles this in CI (GitHub Actions & GameCI).
More in Unity Builds.
Unreal Engine: RunUAT BuildCookRun
Unreal's Unreal Automation Tool (UAT) builds code, cooks content (converts assets to the target platform's format), stages files, paks them and archives the result. The script is Engine/Build/BatchFiles/RunUAT.bat on Windows and RunUAT.sh on Linux and macOS:
Engine\Build\BatchFiles\RunUAT.bat BuildCookRun ^
-project="C:\Projects\Arena\Arena.uproject" ^
-noP4 -platform=Win64 -clientconfig=Shipping ^
-build -cook -stage -pak -archive ^
-archivedirectory="C:\Builds\Arena" -utf8output| Flag | Meaning |
|---|---|
-project= |
the .uproject file |
-platform= |
Win64, Linux, Mac, Android, IOS, … |
-clientconfig= |
Development, Shipping (no console commands, optimised), DebugGame, Test |
-build / -cook / -stage / -pak / -archive |
the steps to run |
-archivedirectory= |
where the finished build goes |
-noP4 |
don't touch Perforce (for Git projects or local builds) |
The Platforms → Package Project menu in the editor runs exactly this command; the Output Log shows the full line, which is the easiest way to discover the flags for a platform. See Unreal Packaging and Unreal Build Tools.
Godot 4: --headless --export-release
Godot exports with the export presets you define in Project → Export, saved in export_presets.cfg (commit it). The command takes the preset's name and an output path:
godot --headless --path . --export-release "Windows Desktop" builds/windows/StarCatcher.exe
godot --headless --path . --export-release "Web" builds/web/index.html
godot --headless --path . --export-pack "Windows Desktop" builds/patch/data.pck # data only- Use the editor binary, not an export template.
- Export templates for the exact Godot version must be installed (on Linux in
~/.local/share/godot/export_templates/<version>/, for example4.5.stable). - The output folder must already exist, and a relative output path is relative to the project folder, not your shell's current directory.
--export-debuguses the debug template;--export-packwrites only the.pck/.zipdata.- Signing secrets don't belong in
export_presets.cfg: Godot 4 keeps export credentials in.godot/export_credentials.cfg(ignored), and Android keystore settings can come from environment variables such asGODOT_ANDROID_KEYSTORE_RELEASE_PATHandGODOT_ANDROID_KEYSTORE_RELEASE_PASSWORD.
A runnable model: one build script for every target
A small wrapper keeps the per-engine details in one table and treats every build the same way: run, check the exit code, check the output exists, and scan the log for errors. Here the engine runs are simulated (exit codes and log lines are given), but the checking logic is what a real wrapper does:
import re
TARGETS = {
"windows": {"out": "builds/windows/StarCatcher.exe",
"exit": 0, "log": ["Build 1.4.2: Succeeded, 214532096 bytes, 0 errors"]},
"web": {"out": "builds/web/index.html",
"exit": 1, "log": ["Assets/Scripts/Shop.cs(42,17): error CS0103: The name 'price' does not exist in the current context",
"Build 1.4.2: Failed, 0 bytes, 1 errors"]},
"linux": {"out": "builds/linux/StarCatcher.x86_64",
"exit": 0, "log": ["Build 1.4.2: Succeeded, 198114304 bytes, 0 errors"]},
}
existing_outputs = {"builds/windows/StarCatcher.exe"} # pretend the linux output went missing
ERROR = re.compile(r"(?P<file>[\w/.]+)\((?P<line>\d+),\d+\): error (?P<code>\w+): (?P<msg>.+)")
failures = 0
for name, t in TARGETS.items():
problems = []
if t["exit"] != 0:
problems.append(f"exit code {t['exit']}")
for line in t["log"]:
m = ERROR.search(line)
if m:
problems.append(f"{m['code']} at {m['file']}:{m['line']}")
if t["exit"] == 0 and t["out"] not in existing_outputs:
problems.append(f"missing output {t['out']}")
failures += bool(problems)
print(f"{name:<8} {'OK' if not problems else 'FAILED: ' + '; '.join(problems)}")
print(f"{failures} of {len(TARGETS)} target(s) failed -> exit {1 if failures else 0}")windows OK
web FAILED: exit code 1; CS0103 at Assets/Scripts/Shop.cs:42
linux FAILED: missing output builds/linux/StarCatcher.x86_64
2 of 3 target(s) failed -> exit 1
The "missing output" check is not paranoia: engines occasionally report success while writing nothing (a wrong path, a disabled scene list). Trust the files, not just the exit code.
Test yourself
Which Unity argument runs a static method from an Editor script?
- -runMethod
- -executeMethod
- -buildMethod
- -batchMethod
What does the 'cook' step in Unreal's BuildCookRun do?
- Compiles C++
- Converts assets into the target platform's runtime format
- Uploads to Steam
- Signs the executable
What must be installed for godot --headless --export-release to work?
- Blender
- Export templates matching the editor version
- Visual Studio
- Nothing