/UnityCommandLine

Extensions to Unity's command line support.

Primary LanguageC#MIT LicenseMIT

Unity Command Line

Unity Command Line extends the Unity's command line.

Supports Unity 2019.1 down to Unity 5.3.

Example

Unity.exe -batchmode
          -executeMethod BuildPlayerCommand.Execute
          -logFile <LogFilePath>
          -nographics
          -projectPath <ProjectDirectory>
          -quit
          -silent-crashes
          -buildTarget Win64
          -buildName HelloWorld
          -applicationIdentifier com.company.example
          -bundleVersion 1.2.3
          -optionDevelopment
          -optionAllowDebugging

Commands

Commands Details
BuildPlayerCommand.Execute Uses BuildPipeline.BuildPlayer to create a build (for example -executeMethod BuildPlayerCommand.Execute -buildTarget Win64 -buildName HelloWorld).
BuildIosCommand.Execute Uses BuildPipeline.BuildPlayer to create an Xcode project (for example -executeMethod BuildIosCommand.Execute).
BuildAssetBundlesCommand.Execute Uses BuildPipeline.BuildAssetBundles to create asset bundle files (for example -executeMethod BuildAssetBundlesCommand.Execute -buildTarget Win64 -bundleName HelloWorld).
ExportPackageCommand.Execute Uses AssetDatabase.ExportPackage to create a .unitypackage (for example -executeMethod ExportPackageCommand.Execute -packageContents "Assets\UnityCommandLine" -packageName UnityCommandLine -optionRecurse).

Options

You can run the Editor and built Unity games with additional commands and information on startup. This section describes the command line options available.

Built-in

Options Details
-batchmode Run Unity in batch mode. You should always use this in conjunction with the other command line arguments, because it ensures no pop-up windows appear and eliminates the need for any human intervention. 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. Tip: To check whether you are running the Editor or Standalone Player 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 when using -batchmode, use the -buildTarget option.
-executeMethod <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 continous 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.
-logFile <LogFilePath> 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 ensure output goes to stdout, which is not the console by default.
-nographics When running in batch mode, do not initialize the 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). Note that -nographics does not allow you to bake GI, because Enlighten requires GPU acceleration.
-noUpm Disables the Unity Package Manager.
-projectPath <ProjectDirectory> Open the project at the given path.
-quit Quit the Unity Editor after other commands have finished executing. Note that this can cause error messages to be hidden (however, they still appear in the Editor.log file).
-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.
-buildTarget Allows the selection of an active build target before loading a project. Possible options are: standalone, Win, Win64, OSXUniversal, Linux, Linux64, LinuxUniversal, iOS, Android, Web, WebStreamed, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, N3DS, tvOS.

BuildPlayerCommand

Options Details
-buildTarget Allows the selection of an active build target before loading a project. Possible options are: standalone, Win, Win64, OSXUniversal, Linux, Linux64, LinuxUniversal, iOS, Android, Web, WebStreamed, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, N3DS, tvOS.
-buildName Sets the output file name (for example -buildName HelloWorld will output Builds\HelloWorld.exe).
-applicationIdentifier Sets PlayerSettings.applicationIdentifier (for example, -applicationIdentifier com.company.example).
-bundleVersion Sets PlayerSettings.bundleVersion (for example, -bundleVersion 1.2.3).
-androidSdkPath Sets EditorPrefs.SetString("AndroidSdkRoot", value) (for example, -androidSdkPath "C:\Users\Me\AppData\Local\Android\Sdk\").
-androidKeyAliasName Sets PlayerSettings.Android.keyaliasName (for example, -androidKeyAliasName com.company.product).
-androidKeyAliasPass Sets PlayerSettings.Android.keyaliasPass (for example, -androidKeyAliasPass password123).
-androidKeyStoreName Sets PlayerSettings.Android.keystoreName (for example, -androidKeyStoreName "C:\Users\John\Documents\hello.keystore").
-androidKeyStorePass Sets PlayerSettings.Android.keystorePass (for example, -androidKeyStorePass 123pass).
-optionDevelopment Adds BuildOptions.Development (for example, -optionDevelopment).
-optionAllowDebugging Adds BuildOptions.AllowDebugging (for example, -optionAllowDebugging).
-optionSymlinkLibraries Adds BuildOptions.SymlinkLibraries (for example, -optionSymlinkLibraries).
-optionForceEnableAssertions Adds BuildOptions.ForceEnableAssertions (for example, -optionForceEnableAssertions).
-optionCompressWithLz4 Adds BuildOptions.CompressWithLz4 (for example, -optionCompressWithLz4).
-optionCompressWithLz4HC Adds BuildOptions.CompressWithLz4HC (for example, -optionCompressWithLz4HC). Only on Unity 2017.2 or higher.
-optionStrictMode Adds BuildOptions.StrictMode(for example, -optionStrictMode).
-optionIncludeTestAssemblies Adds BuildOptions.IncludeTestAssemblies (for example, -optionIncludeTestAssemblies). Only on Unity 2018.1 or higher.

BuildAssetBundlesCommand

Options Details
-buildTarget Allows the selection of an active build target before loading a project. Possible options are: standalone, Win, Win64, OSXUniversal, Linux, Linux64, LinuxUniversal, iOS, Android, Web, WebStreamed, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, N3DS, tvOS.
-bundleName Sets the output file name (for example -bundleName HelloWorld will output AssetBundles\HelloWorld\).
-optionUncompressedAssetBundle Adds BuildAssetBundleOptions.UncompressedAssetBundle (for example, -optionUncompressedAssetBundle).
-optionDisableWriteTypeTree Adds BuildAssetBundleOptions.DisableWriteTypeTree (for example, -optionDisableWriteTypeTree).
-optionDeterministicAssetBundle Adds BuildAssetBundleOptions.DeterministicAssetBundle (for example, -optionDeterministicAssetBundle).
-optionForceRebuildAssetBundle Adds BuildAssetBundleOptions.ForceRebuildAssetBundle (for example, -optionForceRebuildAssetBundle).
-optionIgnoreTypeTreeChanges Adds BuildAssetBundleOptions.IgnoreTypeTreeChanges (for example, -optionIgnoreTypeTreeChanges).
-optionAppendHashToAssetBundleName Adds BuildAssetBundleOptions.AppendHashToAssetBundleName (for example, -optionAppendHashToAssetBundleName).
-optionChunkBasedCompression Adds BuildAssetBundleOptions.ChunkBasedCompression(for example, -optionChunkBasedCompression). Only on Unity 5.3 or higher.
-optionStrictMode Adds BuildAssetBundleOptions.StrictMode (for example, -optionStrictMode). Only on Unity 5.4 or higher.
-optionOmitClassVersions Adds BuildAssetBundleOptions.OmitClassVersions (for example, -optionOmitClassVersions). Only on Unity 5.4.
-optionDryRunBuild Adds BuildAssetBundleOptions.DryRunBuild (for example, -optionDryRunBuild). Only on Unity 5.5 or higher.
-optionDisableLoadAssetByFileName Adds BuildAssetBundleOptions.DisableLoadAssetByFileName (for example, -optionDisableLoadAssetByFileName). Only on Unity 2017.1 or higher.
-optionDisableLoadAssetByFileNameWithExtension Adds BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension (for example, -optionDisableLoadAssetByFileNameWithExtension). Only on Unity 2017.1 or higher.

ExportPackageCommand

Options Details
-packageContents <CommaSeparatedFilesOrFolders> Sets the assetPathNames in AssetDatabase.ExportPackage (for example, -packageContents "Assets\file.dat,Assets\Folder").
-packageName Sets the output file name (for example -packageName HelloWorld will output UnityPackages\HelloWorld.unitypackage).
-optionRecurse Adds ExportPackageOptions.Recurse (for example -optionRecurse).
-optionIncludeDependencies Adds ExportPackageOptions.IncludeDependencies (for example -optionIncludeDependencies).
-optionIncludeLibraryAssets Adds ExportPackageOptions.IncludeLibraryAssets (for example -optionIncludeLibraryAssets).

Installation

Simply clone the repository and copy the Assets\UnityCommandLine folder and you're good to go.

Contributing

Suggestions and contributions are always welcome. Make sure to read the Contribution Guidelines file for more information before submitting a pull request.

Credits

See the Credits file to view the whole list.

License

UnityCommandLine is released under the MIT License. See the LICENSE file for details.