There weren’t a lot of online resources on how to build Unity games from the command line, which was surprising. This would be useful for automating builds, meaning that you don’t need to manually interact with the Unity Editor if you only need to compile your game. If you have a large project, not having to load the Editor is a massive time saver. This can all be done through Unity’s command line arguments.1

## Windows (DOS)#

On Windows, you can run this code directly on the command line, or place it in a Bat script for neatness. Replace the variables projectpath, buildpath, and logpath with the desired paths for your project.

1set projectpath="path\to\project\folder"
2set buildpath="path\to\build.exe"
3set logpath="path\to\log.txt"
4"C:\Program Files\Unity\Editor\Unity.exe" -quit -batchmode -projectpath %projectpath% -buildWindowsPlayer %buildpath% -logFile %logpath%


## Windows PowerShell#

If you prefer PowerShell, you can use this as an alternative on Windows.

1$projectpath = "path\to\project\folder" 2$buildpath    = "path\to\build.exe"
3$logpath = "path\to\log.txt" 4"C:\Program Files\Unity\Editor\Unity.exe" -quit -batchmode -projectpath$projectpath -buildWindowsPlayer $buildpath -logFile$logpath


## Mac#

On Mac, you can run this code on the terminal or inside of a Shell/Bash script.

1#!/bin/bash
2projectpath="path/to/project/folder"
3buildpath="path/to/build.exe"
4logpath="path/to/log.txt"
5/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -projectpath $projectpath -buildWindowsPlayer$buildpath -logFile \$logpath


## Notes#

• You must be logged in to Unity on the machine that is running the builds.
• All of the above commands build for Windows, via the -buildWindowsPlayer argument. You can swap this out to build for other platforms, such as:
• Mac: -buildOSXUniversalPlayer
• Android: -buildTarget Android
• iOS: -buildTarget iOS
• Other supported platforms listed in the Unity User Manual.
• If building for Mac, change the build extension from .exe to .app.
• If you use UnityHub, you may have multiple versions of the editor to choose from. You can specify which one to use by using Unity/Hub/Editor/<Version>/Editor/Unity.exe.
• Ex: C:\Program Files\Unity\Hub\Editor\2019.4.18f1\Editor\Unity.exe -quit -batchmode ...

1. Unity User Manual: Command line arguments: https://docs.unity3d.com/Manual/CommandLineArguments.html ↩︎