Version: 2021.2
命令行参数
Unity Standalone Player command line arguments

Unity Editor command line arguments

Launching Unity

在 macOS 上,在终端中输入以下命令来启动 Unity:

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

在 Windows 上,在命令提示符下输入以下命令来启动 Unity:

"C:\Program Files\Unity\Editor\Unity.exe"

When you launch Unity like this, it receives commands and information on startup, which can be useful for test suites, automated builds and other production tasks.

Configuration arguments

You can run the Editor and build Unity applications with additional commands and information on startup. This page lists the command line arguments you can use to launch and configure a Unity Editor instance.

命令 详细信息:
-createProject <pathname> 在指定路径中创建一个空项目。
-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 overhead when you import assemblies.

This argument is useful if you want to import assemblies that access a Unity API which doesn’t need updating. It’s also useful when you import assemblies which don’t access any Unity APIs (for example, if you have built some or all of your source code 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 needs updating, you might get errors at compile time, run time, or both, that are hard to track.
-disable-gpu-skinning Disable Graphics Processing Unit (GPU) skinning at startup.
-executeMethod <ClassName.MethodName>-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 for 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.
-importPackage <pathname> Import the given asset package. Unity doesn’t display any import dialog.
-job-worker-count <N> Specify the maximum thread count for the Unity JobQueue Job Worker Count. You can also set this value 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 the - option to direct the output to stdout, which by default is not the console.
-noUpm 禁用 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> 在激活 Unity Editor 期间,在登录窗体中输入密码。
-projectPath <pathname> 在指定路径下打开项目。如果路径名包含空格,请将其用引号引起来。
-quit 在其他命令执行完毕后退出 Unity 编辑器。这可能导致错误消息被隐藏(但是,它们仍会出现在 Editor.log 文件中)。
-releaseCodeOptimization 启用发行代码优化模式,覆盖会话的当前默认代码优化模式。
-setDefaultPlatformTextureFormat(仅限 Android) Set the default texture compression 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.
-username <username> 在激活 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 在命令行中打印 Unity 编辑器的版本号,无需启动编辑器。

Batch mode arguments

Use the following arguments to configure Unity’s batch mode. Batch mode enables Unity to run predefined tasks without additional input, which makes batch mode useful for automated tasks like testing. For more information, see Batch mode and built-in coroutine compatibility.

命令 详细信息:
-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 doesn’t run if you omit this command line argument when you launch Unity in batch mode. This might 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.

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 can’t 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.
-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.

Build Arguments

Use the following arguments to build players for various platforms from the command line. For more information about building players with command line arguments, see Unity Standalone Player command line arguments.

命令 详细信息:
-buildLinux64Player <pathname> 构建 64 位独立平台 Linux 播放器(例如,-buildLinux64Player path/to/your/build)。
-buildOSXUniversalPlayer <pathname> 构建 64 位独立平台 Mac OSX 播放器(例如,-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).

Cache server arguments

Use the following arguments to configure Unity’s use of the cache server. For more information, see Cache Server.

命令 详细信息:
-EnableCacheServer 告诉 Unity 使用较新的 Accelerator 缓存服务器。还必须使用 -cacheServerEndpoint 指定地址。
-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> 允许使用较旧的 (v1) 缓存服务器并指定在启动时要连接到的 IP 地址。这将覆盖 Editor Preferences 中存储的配置。使用此命令可将 Unity 的多个实例连接到不同 v1 缓存服务器。

Debugging arguments

命令 详细信息:
-disableManagedDebugger 禁用调试器监听套接字。
-diag-debug-shader-compiler Unity launches only one instance of the Shader Compiler, and forces its timeout to be one hour. Useful for debugging Shader Compiler issues.
-debugCodeOptimization 启用调试代码优化模式,覆盖会话的当前默认代码优化模式。
-enableCodeCoverage EEnables code coverage and allows access to the Coverage API.
-stackTraceLogType Allow detailed debugging. All settings allow None, Script Only and Full to be selected (for example, -stackTraceLogType Full).

Graphics API arguments

Use the following arguments to force the Unity Editor to use a specific graphics API.

命令 详细信息:
-force-d3d11(仅限 Windows) 使 Editor 使用 Direct3D 11 进行渲染。通常,图形 API 取决于 Player Settings(通常默认为 D3D11)。
-force-d3d12(仅限 Windows) 使 Editor 使用 Direct3D 12 进行渲染。通常,图形 API 取决于 Player Settings
-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) 使 Editor 使用 OpenGL for Embedded Systems 进行渲染。Editor 会尝试使用可用的最佳 OpenGL ES 版本以及 OpenGL 驱动程序公开的所有 OpenGL ES 扩展。
-force-glesXY(仅限 Windows) -force-gles 类似,但请求特定的 OpenGL ES 上下文版本。XY 的可接受值:30、31 或 32。
-force-vulkan 使 Editor 使用 Vulkan 进行渲染。通常,图形 API 取决于 Player Settings
-force-clamped 此命令与 -force-glcoreXY 一起使用以阻止 Unity 检查其他 OpenGL 扩展,允许在具有相同代码路径的平台之间运行。

License arguments

Use the following arguments to process a Unity license or run the Unity Editor with different license options.

命令 详细信息:
-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.
-force-free Run the Editor as if there is a free Unity license on the machine, even if a Unity Pro license is installed.
-manualLicenseFile <yourulffile> Step three 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.
-returnlicense 将当前激活的许可证退回到许可证服务器。有关更多信息,请参阅退回许可证
-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’s also good practice to specify the -quit argument.

Metal arguments (macOS only)

Use the following arguments to configure Unity’s use of the Metal graphics API for Apple devices.

命令 详细信息:
-force-device-index 使用 Metal 时,通过传递 GPU 设备的索引,让 Editor 使用特定 GPU 设备(仅限 macOS)。
-force-low-power-device(仅限 macOS) 如果使用 Metal,让 Editor 使用低功耗设备。
-force-metal 使 Editor 使用 Metal 作为默认图形 API(仅限 macOS)。

Profiler arguments

Use the following arguments to configure Unity’s use of the Profiler.

命令 详细信息:
-deepprofiling CPU 性能分析器启用深度性能分析选项。
-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> 此参数可以设置 Unity Profiler 在启动时将性能分析数据流式传输到 .raw 文件。对播放器和 Editor 都有效。
-profiler-capture-frame-count <NumberOfFrames> 此参数可以设置在启动期间流式传输到 .raw 文件时性能分析器应该在性能分析中捕获多少帧。仅对播放器有效。
-profiler-maxusedmemory 默认情况下,Unity Profiler 的 maxUsedMemory 值是 16MB(对于播放器)和 256MB(对于 Editor)。可以在启动时使用此参数将 maxUsedMemory 参数设置为自定义大小(例如,-profiler-maxusedmemory 16777216)。此大小以字节为单位。

示例

*C# script in the project:*

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

以下命令以批处理模式执行 Unity,执行 MyEditorScript.PerformBuild 方法,然后在完成时退出。

Windows:

"C:\Program Files\Unity\Editor\Unity.exe" -quit -batchmode -projectPath "C:\Users\UserName\Documents\MyProject" -executeMethod
MyEditorScript.PerformBuild

macOS:

/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -projectPath ~/UnityProjects/MyProject -executeMethod
MyEditorScript.PerformBuild

Unity Editor special command line arguments

应该只在特殊情况下或者在 Unity 支持人员的指导下使用这些命令行参数。

命令 详细信息:
-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.

Extra Editor arguments from packages

附加编辑器命令行参数在安装这些软件包后可用。

Package 详细信息:
Burst See Burst package documentation.
Test Framework See Unity Test Framework package documentation.
命令行参数
Unity Standalone Player command line arguments
Copyright © 2020 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961