unity-dev-build

Build a Unity project into a Windows development player from the command line, including on machines where batch mode rejects a Unity Personal license. Use when you need a runnable .exe of a Unity game to test, screenshot or ship, and before running unity-autotest.

Produces Build/<Product>/<Product>.exe (a Development build, so logs carry stack traces and the dev console is available) and reports compile errors.

When to use#

  • You changed game code and need to run it outside the editor (self-test, multiplayer with two instances, sharing a build).
  • Not for quick "does it compile" checks if an editor is already open with the project; reading Editor.log is faster.

Steps#

  1. Add the build method to the project (once). Copy scripts/DevBuild.cs to Assets/Editor/DevBuild.cs and set ProductFolder to your product name. It builds all enabled scenes in Build Settings as BuildOptions.Development, logs [DevBuild] Build result: ..., and supports -buildOutput <path>.
  2. Add the build script (once). Copy scripts/build-dev.sh to Tools/build-dev.sh in the project.
  3. Run it from the repo root (Git Bash):
    bash
    1Tools/build-dev.sh

    It closes any editor that has the project open, opens the editor with -executeMethod DevBuild.BuildWindows, waits for the result line or a compile error, prints them, and closes the editor again.

How you know it worked#

The script prints [DevBuild] Build result: Succeeded, size N MB, 0 errors and exits 0. Any error CS… lines are printed above it, and the exit code is 1.

Gotchas#

Batch mode says the license is invalid#

  • Symptom: BatchMode: Unity has not been activated with a valid License and Failed to activate/update license Missing or bad username or password, even though the editor opens fine.
  • Cause: a Unity Personal (entitlement) license is not honoured by -batchmode on some machines and editor versions (seen on 2020.3).
  • Fix: run the build method through the GUI editor with -executeMethod instead of -batchmode -quit. That is what build-dev.sh does. unity build from the Unity CLI uses batch mode, so it fails the same way.

"No valid Unity Editor license found" in GUI mode#

  • Symptom: the editor quits right after start; Editor.log shows Timed-out ... waiting for channel: "LicenseClient-<user>", then No valid Unity Editor license found. The build never runs.
  • Cause: Unity 2020.x waits only about 5 s for its licensing client (Editor/Data/Resources/Licensing/Client/Unity.Licensing.Client.exe). On a busy machine that client took 12 s to answer. unity license still shows the license as fine.
  • Fix: start that client yourself about 15 s before opening the editor. The script does this automatically when no licensing client is running, and exits with code 3 if the error still appears.

Only one editor per project#

Unity locks the project. Close any open editor first (unity close <path> --force). The script does this, so warn the user before running it if they might have unsaved scene changes.

The editor never exits by itself in GUI mode#

-executeMethod in GUI mode leaves the editor open afterwards. The script polls Editor.log for the result line, then closes the editor.

Editor.log is shared#

%LOCALAPPDATA%\Unity\Editor\Editor.log is overwritten each editor start, and it only covers the most recent editor. Don't run two editors at once while building.

Standalone players read config from their working directory#

If the game reads a config file via Directory.GetCurrentDirectory() (SanAndreasUnity does: config.user.json), copy it next to the exe and start the exe from its own folder.

Reference#

  • reference/alt-samp/ has the original from the Alt-SAMP engine (SABFBuild.cs, build-dev.sh), Unity 2020.3.26f1.