Version: Unity 6.2 (6000.2)
Language : English
Create a custom build script
Use build callbacks

Build a player from the command line

You can build a Unity Player from the command line without opening the Unity Editor. This is useful for automated builds in continuous integration (CI) systems and build pipelines.

There are several approaches to building a Player from the command line:

Build type Command line details
Build with a build target Use the -buildTarget argument to specify the target platform, and the -build argument to trigger a Player build.
Build with a build profileA set of customizable configuration settings to use when creating a build for your target platform. More info
See in Glossary
Use the -activeBuildProfile argument to specify a saved build profile, and the -build argument to trigger the build. You need a build profile asset file in your project to use this approach.
Build with a custom script and build target Use the -executeMethod argument to execute a custom build script, along with -buildTarget to specify the target platform.
Build with a custom script and build profile Use the -executeMethod argument to execute a custom build script, along with -activeBuildProfile to specify a saved build profile.

If you want to build a Player without a custom build script, use the -build argument with either -buildTarget or -activeBuildProfile. This approach is similar to selecting Build in the Build Profiles window.

If you have a custom build script, use the -executeMethod argument to specify the static method to execute, along with either -buildTarget or -activeBuildProfile.

Required arguments

The following arguments are required for command line builds:

  • -projectPath <pathname>: Specifies the path to your Unity project.
  • -quit: Exits the Unity Editor after execution completes.

Recommended arguments

The following arguments are optional but recommended for command line builds:

  • -batchmode: Runs Unity in batch mode without the graphical user interface.
  • -logFile <pathname>: Saves the Editor log to a specific file for easier debugging and monitoring.

For a complete list of command line arguments, refer to Unity Editor command line arguments.

Example: Build with a custom script on Windows

The following command executes a custom build script on Windows:

"C:\Program Files\Unity\Hub\Editor\6000.3.XXf1\Editor\Unity.exe" -executeMethod BuildScripts.BuildWindows64 -buildTarget StandaloneWindows64 -batchmode -quit -projectPath "C:\path\to\Project" -logFile C:\Logs\build.log

Example: Build with a custom script on macOS

The following command executes a custom build script on macOS:

/Applications/Unity/Hub/Editor/6000.3.XXf1/Unity.app/Contents/MacOS/Unity -executeMethod BuildScripts.BuildMacOS -buildTarget StandaloneOSX -batchmode -quit -projectPath "/path/to/Project" -logFile ~/Logs/build.log

Note: Adjust the Unity Editor path in the examples to match the version of Unity you want to use, or replace the path entirely if your Unity Editor is installed in a different location.

Additional resources

Create a custom build script
Use build callbacks