You can run Unity from the command line (from the macOS Terminal or the Windows Command Prompt).
On macOS, type the following into the Terminal to launch Unity:
/Applications/Unity/Unity.app/Contents/MacOS/Unity
On Windows, type the following into the Command Prompt to launch Unity:
"C:\Program Files\Unity\Editor\Unity.exe"
When you launch Unity like this, it receives commands and information on startup, which can be very useful for test suites, automated builds and other production tasks.
Note: Use the same method to launch standalone Unity applications.
You can run the Editor and build Unity applications with additional commands and information on startup. This section describes the command line options available.
Command | Details |
---|---|
-accept-apiupdate |
Use this command line option to specify that APIUpdater should run when Unity is launched in batch mode. Example: unity.exe -accept-apiupdate -batchmode [other params] The APIUpdater will not run if you omit this command line argument when you launch Unity in batch mode. This can lead to compiler errors. |
-batchmode
|
Run Unity in batch mode. In batch mode, Unity runs command line arguments without the need for human interaction. It also suppresses pop-up windows that require human interaction (such as the Save Scene window); however, the Unity Editor itself opens as usual. You should always run Unity in batch mode when using command line arguments, because it allows automation to run without interruption. When an exception occurs during execution of the script code, the Asset server updates fail, or other operations fail, Unity immediately exits with return code 1. Note that in batch mode, Unity sends a minimal version of its log output to the console. However, the Log Files still contain the full log information. You cannot open a project in batch mode while the Editor has the same project open; only a single instance of Unity can run at a time. To check whether the Editor or Standalone Player is running in batch mode, use the Application.isBatchMode operator. If the project has not yet been imported when using -batchmode , the target platform is the default one. To force a different platform, use the -buildTarget option. |
-buildLinux64Player <pathname> |
Build a 64-bit standalone Linux player (for example, -buildLinux64Player path/to/your/build ). |
-buildOSXUniversalPlayer <pathname> |
Build a 64-bit standalone Mac OSX player (for example, -buildOSXUniversalPlayer path/to/your/build.app ). |
-buildTarget <name> |
Select an active build target before loading a project. Possible options are: Standalone, Win, Win64, OSXUniversal, Linux64, iOS, Android, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, tvOS. |
-buildWindowsPlayer <pathname> |
Build a 32-bit standalone Windows player (for example, -buildWindowsPlayer path/to/your/build.exe ). |
-buildWindows64Player <pathname> |
Build a 64-bit standalone Windows player (for example, -buildWindows64Player path/to/your/build.exe ). |
-createManualActivationFile |
Step one of a three-step process to manually activate a Unity license. For more information, see Generate a license activation file (.alf ) from the command line. |
-createProject <pathname> |
Create an empty project at the given path. |
-debugCodeOptimization |
Enables debug code optimization mode, overriding the current default code optimization mode for the session. |
-deepprofiling |
Enable Deep Profiling option for the CPU profiler. |
-disable-assembly-updater <assembly1 assembly2> |
Specify a space-separated list of assembly names as parameters for Unity to ignore on automatic updates. The space-separated list of assembly names is optional: pass the command line options without any assembly names to ignore all assemblies, as in example 1. Example 1 unity.exe -disable-assembly-updater Example 2 unity.exe -disable-assembly-updater A1.dll subfolder/A2.dll Example 2 has two assembly names, one with a pathname. Example 2 ignores A1.dll , no matter what folder it is stored in, and ignores A2.dll only if it is stored under subfolder folder:If you list an assembly in the -disable-assembly-updater command line parameter (or if you don’t specify assemblies), Unity logs the following message to Editor.log: [Assembly Updater] warning: Ignoring assembly [assembly_path] as requested by command line parameter.”). Use this to avoid unnecessary API Updater overheads when importing assemblies. It is useful for importing assemblies which access a Unity API when you know the Unity API doesn’t need updating. It is also useful when importing assemblies which do not access Unity APIs at all (for example, if you have built your source code, or some of it, outside of Unity, and you want to import the resulting assemblies into your Unity project). Note: If you disable the update of any assembly that does need updating, you might get errors at compile time, run time, or both, that are hard to track. |
-disableManagedDebugger |
Disables the debugger listen socket. |
-diag-debug-shader-compiler |
Unity launches only one instance of the ShaderA program that runs on the GPU. More info See in Glossary Compiler, and forces its timeout to be one hour. Useful for debugging Shader Compiler issues. |
-disable-gpu-skinning |
Disable GPU skinningThe process of binding bone joints to the vertices of a character’s mesh or ‘skin’. Performed with an external tool, such as Blender or Autodesk Maya. More info See in Glossary at startup. |
-enableCodeCoverage |
Enables code coverage and allows access to the Coverage API. |
-executeMethod <ClassName.MethodName> or -executeMethod <NamespaceName.ClassName.MethodName>
|
Execute the static method as soon as Unity opens the project, and after the optional Asset server update is complete. You can use this to do tasks such as continuous integration, performing Unit Tests, making builds or preparing data. To return an error from the command line process, either throw an exception which causes Unity to exit with return code 1, or call EditorApplication.Exit with a non-zero return code. To pass parameters, add them to the command line and retrieve them inside the function using System.Environment.GetCommandLineArgs . To use -executeMethod , you need to place the enclosing script in an Editor folder. The method you execute must be defined as static. |
-exportPackage <exportAssetPath1 exportAssetPath2 ExportAssetPath3 exportFileName> |
Export a package, given a path (or set of given paths). In this example exportAssetPath is a folder (relative to the Unity project root) to export from the Unity project, and exportFileName is the package name. This option only exports whole folders at a time. You normally need to use this command with the -projectPath argument. |
-force-d3d11 (Windows only) |
Make the Editor use Direct3D 11 for rendering. Normally the graphics API depends on Player SettingsSettings that let you set various player-specific options for the final game built by Unity. More info See in Glossary (typically defaults to D3D11). |
-force-d3d12 (Windows only) |
Make the Editor use Direct3D 12 for rendering. Normally the graphics API depends on Player Settings. |
-force-device-index |
When using Metal, make the Editor use a particular GPU device by passing it the index of that GPU (macOS only). |
-force-metal |
Make the Editor use Metal as the default graphics API (macOS only). |
-force-glcore |
Make the Editor use OpenGL 3/4 core profile for rendering. The Editor tries to use the best OpenGL version available and all OpenGL extensions exposed by the OpenGL drivers. If the platform isn’t supported, the editor uses Direct3D. |
-force-glcoreXY |
Similar to -force-glcore , but requests a specific OpenGL context version. Accepted values for XY: 32, 33, 40, 41, 42, 43, 44 or 45. |
-force-gles (Windows only) |
Make the Editor use OpenGL for Embedded Systems for rendering. The Editor tries to use the best OpenGL ES version available, and all OpenGL ES extensions exposed by the OpenGL drivers. |
-force-glesXY (Windows only) |
Similar to -force-gles , but requests a specific OpenGL ES context version. Accepted values for XY: 30, 31 or 32. |
-force-vulkan |
Make the Editor use Vulkan for rendering. Normally the graphics API depends on Player Settings. |
-force-clamped |
Use this with -force-glcoreXY to prevent Unity from checking for additional OpenGL extensions, allowing it to run between platforms with the same code paths. |
-force-free |
Make the Editor run as if there is a free Unity license on the machine, even if a Unity Pro license is installed. |
-force-low-power-device (macOS only) |
If you use Metal, make the Editor use a low power device. |
-importPackage <pathname> |
Import the given asset packageA collection of files and data from Unity projects, or elements of projects, which are compressed and stored in one file, similar to Zip files, with the .unitypackage extension. Asset packages are a handy way of sharing and re-using Unity projects and collections of assets. More infoSee in Glossary. No import dialog is shown. |
-job-worker-count <N> |
Specify the maximum thread count for the Unity JobQueue Job Worker Count. You can also specify it as job-worker-count=<N> in boot.config for the Unity Standalone Player. |
-logFile <pathname> |
Specify where Unity writes the Editor or Windows/Linux/OSX standalone log file. To output to the console, specify - for the path name. On Windows, specify - option to make the output go to stdout , which is not the console by default. |
-manualLicenseFile <yourulffile> |
Step three of a three-step process to manually activate a Unity license. For more information, see Finish your Unity license activation from the command line. |
-nographics |
When you run this in batch mode, it does not initialize the graphics device. You can then run automated workflows on machines that don’t have a GPU. Automated workflows only work when you have a window in focus, otherwise you can’t send simulated input commands. -nographics does not allow you to bake GI, because Enlighten requires GPU acceleration. |
-noUpm |
Disables the Unity Package Manager. |
-openfile <path> |
Open the project from a path to a scene or package file. Alternatively, you can use the -projectPath argument. |
-password <password> |
Enter a password into the log-in form during the activation of the Unity Editor. |
-profiler-enable |
Profile the start-up of a Player or the Editor. When you use this argument with a Player, it has the same effect as building the Player with the Autoconnect Profiler option enabled in Build Settings. When you use this argument with the Editor, it starts collecting and displaying Profiler information in the Profiler window on start-up of the Editor. |
-profiler-log-file <Path/To/Log/File.raw> |
This argument sets up the Unity Profiler to stream the profile data to a .raw file on startup. It works for both Players and the Editor. |
-profiler-capture-frame-count <NumberOfFrames> |
This argument sets how many frames the Profiler should capture in a profile when streaming to a .raw file on start-up. It only works on Players. |
-profiler-maxusedmemory |
By default, maxUsedMemory for the Unity ProfilerA window that helps you to optimize your game. It shows how much time is spent in the various areas of your game. For example, it can report the percentage of time spent rendering, animating, or in your game logic. More infoSee in Glossary is 16MB for Players and 256MB for the Editor. You can use this argument to set the maxUsedMemory parameter to a custom size at start-up (for example, -profiler-maxusedmemory 16777216 ). The size is set in bytes. |
-systemallocator |
Forces the platform to use the system allocator. This can be useful if you want to use tools like address sanitizers to debug memory issues. You should only use this option for debugging purposes. Note: If you use the system allocator on Android 11 ARM64, the application might crash with “Using memoryadresses from more than 16GB of memory” error. This is a known issue. |
-projectPath <pathname> |
Open the project at the given path. If the pathname contains spaces, enclose it in quotes. |
-quit |
Quit the Unity Editor after other commands have finished executing. This can cause error messages to be hidden (but they still appear in the Editor.log file). |
-releaseCodeOptimization |
Enables release code optimization mode, overriding the current default code optimization mode for the session. |
-returnlicense |
Return the currently active license to the license server. For more information, see Returning your license. |
-serial <serial> |
Activate your Unity license with the specified serial number. For more information, see Activating a license from the command line. Note: When you use this argument, you must also use the -batchmode argument. It is also good practice to specify the -quit argument. |
-setDefaultPlatformTextureFormat (Android only) |
Set the default texture compression3D Graphics hardware requires Textures to be compressed in specialized formats which are optimized for fast Texture sampling. More info See in Glossary to the desired format before you import a texture or build the project. This is so you don’t have to import the texture again with the format you want. The available formats are dxt, pvrtc, atc, etc, etc2, and astc. |
-silent-crashes |
Prevent Unity from displaying the dialog that appears when a Standalone Player crashes. This argument is useful when you want to run the Player in automated builds or tests, where you don’t want a dialog prompt to obstruct automation. |
-stackTraceLogType |
Allow detailed debugging. All settings allow None, Script Only and Full to be selected (for example, -stackTraceLogType Full ). |
-username <username> |
Enter a username into the log-in form during the activation of the Unity Editor. |
-vcsMode <mode> |
Set the version control mode. Available modes are "Visible Meta Files" , "Hidden Meta Files" , Perforce , and PlasticSCM . You can use additional flags to fill out the configuration fields for the given version control mode. These flags are based on the Provider.GetActiveConfigFields method. For example, you can use the -vcPerforceUsername , -vcPerforcePassword , -vcPerforceWorkspace and -vcPerforceServer to set the Perforce username, workspace and server fields.Note: <mode> arguments that contain spaces must be wrapped in double quotes (" ). |
-vcsModeSession <mode> |
Set the version control mode for this session. Available modes are "Visible Meta Files" , "Hidden Meta Files" , Perforce , and PlasticSCM . You can use additional flags to fill out the configuration fields for the given version control mode. These flags are based on the Provider.GetActiveConfigFields method. For example, you can use the -vcPerforceUsername , -vcPerforcePassword , -vcPerforceWorkspace and -vcPerforceServer to set the Perforce username, workspace and server fields.Note: <mode> arguments that contain spaces must be wrapped in double quotes (" ). |
-version |
Print the version number of the Unity Editor in the command line, without launching the Editor. |
-EnableCacheServer |
Tells Unity to use the newer Accelerator Cache Server. You must also use -cacheServerEndpoint to specify the address. |
-cacheServerEndpoint |
Specifies the endpoint address if you are using the newer Accelerator Cache Server. Example: -cacheServerEndpoint 127.0.0.1:10080 . This overrides any configuration stored in the Editor Preferences. Use this to connect multiple instances of Unity to different Cache Servers. |
-cacheServerNamespacePrefix |
Set the namespace prefix for the newer Accelerator Cache Server. Used to group data together on the Cache Server. Example: -cacheServerNamespacePrefix MyProject
|
-cacheServerEnableDownload |
Enable downloading from the newer Accelerator Cache Server. Example: -cacheServerEnableDownload true
|
-cacheServerEnableUpload |
Enable uploading to the newer Accelerator Cache Server. Example: -cacheServerEnableUpload false
|
-CacheServerIPAddress <host:port> |
Enables usage of the older (v1) Cache Server, and specifies the IP Address to connect to on startup. This overrides any configuration stored in the Editor Preferences. Use this to connect multiple instances of Unity to different v1 Cache Servers. |
C# script in the project:
using UnityEditor;
class MyEditorScript
{
static void PerformBuild ()
{
string[] scenes = { "Assets/MyScene.unity" };
BuildPipeline.BuildPlayer(scenes, ...);
}
}
The following command executes Unity in batch mode, executes the MyEditorScript.PerformBuild
method, and then quits upon completion.
Windows:
"C:\Program Files\Unity\Editor\Unity.exe" -quit -batchmode -projectPath "C:\Users\UserName\Documents\MyProject" -executeMethod MyEditorScript.PerformBuild
Mac OS:
/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -projectPath ~/UnityProjects/MyProject -executeMethod MyEditorScript.PerformBuild
You should only use these under special circumstances, or when directed by Unity Support.
Command | Details |
---|---|
-enableIncompatibleAssetDowngrade |
Use this when you have Assets made by a newer, incompatible version of Unity, that you want to downgrade to work with your current version of Unity. When you enable this, Unity presents you with a dialog asking for confirmation of this downgrade if you attempt to open a project that would require it. Note: This procedure is unsupported and highly risky, and should only be used as a last resort. |
Additional Editor command line arguments are available when these packages are installed.
Package | Details |
---|---|
Burst | See Burst package documentation. |
Test Framework | See Unity Test Framework package documentation. |
Standalone players built with Unity also understand some command line arguments:
Command | Details |
---|---|
-batchmode |
Run the game in “headless” mode. The game does not display anything or accept user input. This is useful for running servers for networked games. |
-disable-gpu-skinning |
Disable GPU skinning at startup. |
-force-d3d11 (Windows only) |
Force the game to use Direct3D 11 for rendering. |
-force-d3d11-singlethreaded |
Force DirectX 11.0 to be created with a D3D11_CREATE_DEVICE_SINGLETHREADED flag. |
-force-d3d12 (Windows only) |
Force the game to use Direct3D 12 for rendering. |
-force-device-index |
Make the Standalone Player use a particular GPU device by passing it the index of that GPU. This option is supported for D3D11, D3D12, Metal, and Vulkan graphics APIs, but is not supported for OpenGL. |
-force-metal (macOS only) |
Make the Standalone Player use Metal as the default graphics API. |
-force-glcore |
Force the game to use OpenGL core profile for rendering. The Editor tries to use the best OpenGL version available, and all OpenGL extensions exposed by the OpenGL drivers. If the platform isn’t supported, Direct3D is used. |
-force-glcoreXY |
Similar to -force-glcore , but requests a specific OpenGL context version. Accepted values for XY: 32, 33, 40, 41, 42, 43, 44 or 45. |
-force-vulkan |
Force the game to use Vulkan for rendering. |
-force-clamped |
Use this together with -force-glcoreXY to prevent checking for additional OpenGL extensions, allowing it to run between platforms with the same code paths. |
-force-low-power-device (macOS only) |
Make the Standalone Player use a low power device. |
-force-wayland |
Activate experimental Wayland support when running a Linux player. |
-monitor N |
Run Standalone Player on the specified monitor, indicated by a 1-based index number. |
-nographics |
When you run this in batch mode, it does not initialize a graphics device. This makes it possible to run your automated workflows on machines that don’t have a GPU. |
-nolog |
Do not produce an output log. Normally Unity writes the output_log.txt in the Log Files folder, where the Debug.Log output is printed. |
-no-stereo-rendering |
Turn off stereo rendering. |
-parentHWND <HWND> delayed (Windows only) |
Embed the Windows Standalone application into another application. When you use this, you need to pass the parent application’s window handle (‘HWND’) to the Windows Standalone application. When you pass -parentHWND 'HWND' delayed , the Unity application is hidden while it is running. You must also call SetParent from the Microsoft Developer library for Unity in the application. Microsoft’s SetParent embeds the Unity window. When it creates Unity processes, the Unity window respects the position and size provided as part of the Microsoft’s STARTUPINFO structure. To resize the Unity window, check its GWLP_USERDATA in Microsoft’s GetWindowLongPtr function. Its lowest bit is set to 1 when the graphics initialize and it’s safe to resize. Its second lowest bit is set to 1 after the Unity splash screen finishes displaying.For more information, see this example: EmbeddedWindow.zip |
-popupwindow |
Create the window as a a pop-up window, without a frame. This command is not supported on macOS. |
-screen-fullscreen |
Override the default full-screen state. This must be 0 or 1. |
-screen-height |
Override the default screen height. This must be an integer from a supported resolution. |
-screen-width |
Override the default screen width. This must be an integer from a supported resolution. |
-screen-quality |
Override the default screen quality. Example usage would be: /path/to/myGame -screen-quality Beautiful . The supported options match the Quality Settings names. |
-single-instance (Linux and Windows only) |
Run only one instance of the application at the time. If another instance is already running then launching it again with -single-instance focuses the existing one. |
-vrmode <devicetype> |
Launch with a specific VR device. See Virtual RealityA system that immerses users in an artificial 3D world of realistic images and sounds, using a headset and motion tracking. More info See in Glossary for details. |
-window-mode (Windows only) |
Override fullscreen windowing mode. Accepted values are exclusive or borderless . See Standalone Player settings for details. |
Universal Windows Apps don’t accept command line arguments by default, so to pass them you need to call a special function from MainPage.xaml.cs/cpp or MainPage.cs/cpp. For example:
appCallbacks.AddCommandLineArg("-nolog");
You should call this before the appCallbacks.Initialize()
function.
Command | Details |
---|---|
-nolog |
Don’t produce UnityPlayer.log. |
-force-driver-type-warp |
Force the DirectX 11.0 driver type WARP device (see Microsoft’s documentation on Windows Advanced Rasterization Platform for more information). |
-force-d3d11-singlethreaded |
Force DirectX 11.0 to be created with a D3D11_CREATE_DEVICE_SINGLETHREADED flag. |
-force-gfx-direct |
Force single threaded rendering. |
-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. |
“accept-apiupdate” command line option added in Unity 2017.2 NewIn20172
“-force-clamped” command line argument added in Unity 2017.3 NewIn20172
Tizen support discontinued in 2017.3 NewIn20173
“noUpm”, “setDefaultPlatformTextureFormat” and “CacheServerIPAddress” command line options added in Unity 2018.1 NewIn20181
“Application.isBatchMode” operator added in 2018.2 NewIn20182
To pass additional command line arguments, expand the updateUnityCommandLineArguments
method in the UnityPlayerActivity
class.
public class UnityPlayerActivity extends Activity implements IUnityPlayerLifecycleEvents
{
...
protected String updateUnityCommandLineArguments(String cmdLine)
{
return (cmdLine == null ? "" : " ") + "-force-vulkan -quit";
}
}