Previous
Streaming Assets
Next
Running Editor Script Code on Launch
Suggest a change

Command line arguments

Typically, Unity will be launched by double-clicking its icon from the desktop but it is also possible to run it from the command line (ie, the MacOS Terminal or the Windows Command Prompt). When launched in this way, Unity can receive commands and information on startup, which can be very useful for test suites, automated builds and other production tasks.

Under MacOS, you can launch Unity from the Terminal by typing:-

 /Applications/Unity/Unity.app/Contents/MacOS/Unity

…while under Windows, you should type

 "C:\Program Files (x86)\Unity\Editor\Unity.exe"

…at the command prompt.

Standalone Unity games can be launched in a similar way.

Options

As mentioned above, the editor and also built games can optionally be supplied with additional commands and information on startup. This is done using the following command line options:-

-batchmode Run Unity in batch mode. This should always be used in conjunction with the other command line arguments as it ensures no pop up windows appear and eliminates the need for any human intervention. When an exception occurs during execution of script code, asset server updates fail or other operations fail Unity will immediately exit with return code 1. Note that in batch mode, Unity will send a minimal version of its log output to the console. However, the Log Files still contain the full log information. Note that opening a project in batch mode whilst the Editor has the same project open is not supported. Only a single instance of Unity can run at a time.
-quit Quit the Unity editor after other commands have finished executing. Note that this can cause error messages to be hidden (but they will show up in the Editor.log file).
-force-opengl (Windows only) Make the editor use OpenGL for rendering, even if Direct3D is available. Normally Direct3D is used but OpenGL is used if Direct3D 9.0c is not available.
-force-d3d9 (Windows only) Make the editor use Direct3D 9 for rendering. This is the default, so normally there’s no reason to pass it.
-force-d3d11 (Windows only) Make the editor use Direct3D 11 for rendering.
-buildWindowsPlayer <pathname> Build a 32-bit standalone Windows player (e.g. -buildWindowsPlayer path/to/your/build.exe).
-buildWindows64Player <pathname> Build a 64-bit standalone Windows player (e.g. -buildWindows64Player path/to/your/build.exe).
-buildOSXPlayer <pathname> Build a 32-bit standalone Mac OSX player (e.g. -buildOSXPlayer path/to/your/build.app).
-buildOSX64Player <pathname> Build a 64-bit standalone Mac OSX player (e.g. -buildOSX64Player path/to/your/build.app).
-buildOSXUniversalPlayer <pathname> Build a combined 32-bit and 64-bit standalone Mac OSX player (e.g. -buildOSXUniversalPlayer path/to/your/build.app).
-buildLinux32Player <pathname> Build a 32-bit standalone Linux player (e.g. -buildLinux32Player path/to/your/build).
-buildLinux64Player <pathname> Build a 64-bit standalone Linux player (e.g. -buildLinux64Player path/to/your/build).
-buildLinuxUniversalPlayer <pathname> Build a combined 32-bit and 64-bit standalone Linux player (e.g. -buildLinuxUniversalPlayer path/to/your/build).
-buildWebPlayer <pathname> Build a WebPlayer (e.g. -buildWebPlayer path/to/your/build).
-buildWebPlayerStreamed <pathname> Build a streamed WebPlayer (e.g. -buildWebPlayerStreamed path/to/your/build).
-buildTarget <name> Allows the selection of an active build target before a project is loaded.
-importPackage <pathname> Import the given package. No import dialog is shown.
-createProject <pathname> Create an empty project at the given path.
-projectPath <pathname> Open the project at the given path.
-logFile <pathname> Specify where the Editor or Windows/Linux standalone log file will be written.
-assetServerUpdate <IP[:port] projectName username password [r <revision>]> Force an update of the project in the Asset Server given by IP:port. The port is optional and if not given it is assumed to be the standard one (10733). It is advisable to use this command in conjunction with the -projectPath argument to ensure you are working with the correct project. If no project name is given then the last project opened by Unity is used. If no project exists at the path given by -projectPath then one is created automatically.
-exportPackage <exportAssetPath1 exportAssetPath2 ExportAssetPath3 exportFileName> Exports a package given a path (or set of given paths). exportAssetPath is a folder (relative to to the Unity project root) to export from the Unity project and exportFileName is the package name. Currently, this option can only export whole folders at a time. This command normally needs to be used with the -projectPath argument.
-nographics (Windows only) When running in batch mode, do not initialize graphics device at all. This makes it possible to run your automated workflows on machines that don’t even have a GPU (automated workflows only work, when you have a window in focus, otherwise you can’t send simulated input commands).
-executeMethod <ClassName.MethodName> Execute the static method as soon as Unity is started, the project is open and after the optional asset server update has been performed. This can be used to do continous integration, perform Unit Tests, make builds, prepare some data, etc. If you want to return an error from the commandline process you can either throw an exception which will cause Unity to exit with 1 or else call EditorApplication.Exit with a non-zero code. If you want to pass parameters you can add them to the command line and retrieve them inside the method using System.Environment.GetCommandLineArgs.

To use -executeMethod, you need to place the enclosing script in an Editor folder. The method to be executed must be defined as static.

// C# example
using UnityEditor;
class MyEditorScript
{
     static void PerformBuild ()
     {
         string[] scenes = { "Assets/MyScene.unity" };
         BuildPipeline.BuildPlayer(scenes, ...);
     }
}


// JavaScript example
static void PerformBuild ()
{
    string[] scenes = { "Assets/MyScene.unity" };
    BuildPipeline.BuildPlayer(scenes, ...);
}


Example usage

The following command executes Unity in batch mode, executes the MyEditorScript.MyMethod method and then quits upon completion.

Windows: C:\program files\Unity\Editor\Unity.exe -quit -batchmode -executeMethod MyEditorScript.MyMethod

Mac OS: /Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod MyEditorScript.MyMethod

The next command executes Unity in batch mode and updates from the asset server using the supplied project path. The method is executed after all assets have been downloaded and imported from the asset server. After the method has finished execution, Unity automatically quits.

/Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -projectPath ~/UnityProjects/AutobuildProject -assetServerUpdate 192.168.1.1 MyGame AutobuildUser l33tpa33 -executeMethod MyEditorScript.PerformBuild -quit

Unity Standalone Player command line arguments

Standalone players built with Unity also understand some command line arguments:

-batchmode Run the game in “headless” mode. The game will not display anything or accept user input. This is mostly useful for running servers for networked games.
-force-opengl (Windows only) Make the game use OpenGL for rendering, even if Direct3D is available. Normally Direct3D is used but OpenGL is used if Direct3D 9.0c is not available.
-force-d3d9 (Windows only) Make the game use Direct3D 9 for rendering. This is the default, so normally there’s no reason to pass it.
-force-d3d11 (Windows only) Make the game use Direct3D 11 for rendering.
-single-instance (Linux & Windows only) Allow only one instance of the game to run at the time. If another instance is already running then launching it again with -single-instance will just focus the existing one.
-nolog (Linux & Windows only) Do not produce output log. Normally output_log.txt is written in the *_Data folder next to the game executable, where Debug.Log output is printed.
-force-d3d9-ref (Windows only) Make the game run using Direct3D’s “Reference” software renderer. The DirectX SDK has to be installed for this to work. This is mostly useful for building automated test suites, where you want to ensure rendering is exactly the same no matter what graphics card is being used.
-adapter N (Windows only) Allows the game to run full-screen on another display. The N maps to a Direct3D display adaptor. In most cases there is a one-to-one relationship between adapters and video cards. On cards that support multi-head (they can drive multiple monitors from a single card) each “head” may be its own adapter.
-popupwindow (Windows only) The window will be created as a a pop-up window (without a frame).
-screen-width (Linux & Windows only) Overrides the default screen width. This must be an integer from a supported resolution.
-screen-height (Linux & Windows only) Overrides the default screen height. This must be an integer from a supported resolution.
-screen-quality (Linux only) Overrides the default screen quality. Example usage would be: /path/to/myGame -screen-quality Beautiful
-nographics (Linux & Windows only) When running in batch mode, do not initialize graphics device at all. This makes it possible to run your automated workflows on machines that don’t even have a GPU.

Editor Installer

The following options can be used when installing the Unity Editor from command line:

/S (Windows only) Performs a silent (no questions asked) install.
/D=PATH (Windows only) Sets the default install directory. Useful when combined with the silent install option.

Example usage

Install Unity silently to E:\Development\Unity.

Windows: UnitySetup.exe /S /D=E:\Development\Unity

Windows Store Command line arguments

Windows Store Apps don’t accept command line arguments by default, so to pass them you have to call a special function from App.xaml.cs/cpp or App.cs/cpp. For example,

appCallbacks.AddCommandLineArg("-nolog");

You should call this before the appCallbacks.Initialize*() function.

-nolog Don’t produce UnityPlayer.log.
-force-driver-type-warp Force DirectX 11.0 WARP device (More info http://msdn.microsoft.com/en-us/library/gg615082.aspx)
-force-gfx-direct Force single threaded rendering.
-force-d3d11-no-singlethreaded Force DirectX 11.0 to be created without D3D11_CREATE_DEVICE_SINGLETHREADED flag.
-force-feature-level–9–1 Force DirectX 11.0 feature level 9.1.
-force-feature-level–9–2 Force DirectX 11.0 feature level 9.2.
-force-feature-level–9–3 Force DirectX 11.0 feature level 9.3.
-force-feature-level–10–0 Force DirectX 11.0 feature level 10.0.
-force-feature-level–10–1 Force DirectX 11.0 feature level 10.1.
-force-feature-level–11–0 Force DirectX 11.0 feature level 11.0.
Previous
Streaming Assets
Next
Running Editor Script Code on Launch
Your name (optional):
Your email (optional):
Please write your suggestion here: