ストリーミングアセット
起動時エディタスクリプト実行

コマンドライン引数

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

一般的には,Unityを起動する時はデスクトップからアイコン起動しますが,コマンドライン実行(すなわちMacOSターミナルまたはWindowsコマンドプロンプト)も可能です。こうして起動するとUnityは起動時にコマンドや情報を受け取ることが出来てテスト スイート,自動ビルド,またはその他の本番タスクに非常に役立ちます。

MacOSでTerminalからUnityを起動するには次の通りに入力します:-

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

… Windowsでの入力は

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

…をコマンドプロンプトから行います。

スタンドアローンUnityゲームは同様の方法で起動します。

オブション

上で述べた通り,エディターに加えてビルド するゲームもスタートアップの時に追加のコマンドおよび情報をオプションとして提供出来ます。これは次のコマンドライン引数を使用して行います:-

-batchmode バッチモードでUnityを実行。これは常に他のコマンドライン引数との組み合わせで使用すべきでポップアップウィンドウが表示され人の手が介在する必要がありません。もし例外エラーがスクリプトコード実行時に発生するか,アセットサーバの更新が失敗するか,またはその他の処理が失敗した場合にUnityは直ちに戻り値 1 で終了します。バッチモードではUnityは最小限のログ出力をコンソールに送信することに留意して下さい。しかし Log Files には完全なログ情報が含まれます。 プロジェクトをバッチモードでプロジェクトを開くときにエディターも同じプロジェクトを開くことはサポートされていないことに留意して下さい。Unity のインスタンスは同時にひとつしか実行することが出来ません。
-quit 他のコマンド実行の終了後にUnityエディターを終了します。これによりエラーメッセージが隠される場合があることに留意して下さい。
-force-opengl (Windows only) Direct3Dが利用可能であったとしても強制的にレンダリングでOpenGLを使用するようにします。通常Direct3Dが使用されますが,Direct3D 9.0cが利用可能でない場合OpenGLが使用されます。
-force-d3d9 (Windows only) 強制的にレンダリングでDirect3D 9を使用します。これはデフォルト値のため,渡す意味がありません。
-force-d3d11 (Windows only) 強制的にレンダリングでDirect3D 11を使用します。
-buildWindowsPlayer <pathname> スタンドアローン Windows プレイヤーをビルド(例えば, -buildWindowsPlayer path/to/your/build.exe)
-buildWindows64Player <pathname> スタンドアローン Mac OSX player をビルド(例えば, -buildOSXPlayer path/to/your/build.app)
-buildOSXPlayer <pathname> 32-bitスタンドアロン Mac OS X player をビルド(例えば, -buildOSXPlayer path/to/your/build.app)
-buildOSX64Player <pathname> 64-bitスタンドアロン Mac OS X player をビルド(例えば, -buildOSX64Player path/to/your/build.app)
-buildOSXUniversalPlayer <pathname> 32-bit および 64-bit を組み合わせた Mac OS X playerをビルド (e.g. -buildOSXUniversalPlayer path/to/your/build.app).
-buildLinux32Player <pathname> 32-bitスタンドアロン Linux player をビルド(例えば, -buildLinux32Player path/to/your/build)
-buildLinux64Player <pathname> 64-bitスタンドアロン Linux player をビルド(例えば, -buildLinux64Player path/to/your/build)
-buildLinuxUniversalPlayer <pathname> 32-bit および 64-bit を組み合わせた Linux playerをビルド (e.g. -buildLinuxUniversalPlayer path/to/your/build)
-buildWebPlayer <pathname> ウェブプレイヤーをビルド (例えば, -buildWebPlayer path/to/your/build).
-buildWebPlayerStreamed <pathname> ストリーミング ウェブプレイヤーをビルド (例えば, -buildWebPlayerStreamed path/to/your/build)
-buildTarget <name> プロジェクトのロード前にアクティブなビルドターゲットを選択可能にします
-importPackage <pathname> 特定の パッケージ をインポート。インポートダイアログは表示されません。
-createProject <pathname> 特定のパスに空のプロジェクトを作成
-projectPath <pathname> 特定のパスでプロジェクトを開く
-logFile <pathname> エディターまたは Windows / Linux スタンドアローンのログファイルが書き込みされる場所を指定。
-assetServerUpdate <IP[:port] projectName username password [r <revision>]> 強制的に IP:port で指定された Asset Server の中のプロジェクト更新を行なう。ポート情報は任意であり,ない場合は標準のポート (10733)を使用。このコマンドは -projectPath 引数と組み合わせて正しいプロジェクトで作業していることを保証したうえで使用することを推奨します。もしプロジェクト名がない場合,Unityで最も最近開かれたファイルが使用されます。もし -projectPath にプロジェクトが存在しない場合,プロジェクトが新たに作成されます。
-exportPackage <exportAssetPath1 exportAssetPath2 ExportAssetPath3 exportFileName> 特定のパス(または複数のパス)にエクスポート。 exportAssetPath はUnityプロジェクトからエクスポートするフォルダ(Unityプロジェクトのルートディレクトリに対する相対パス指定)であり,exportFileName はパッケージの名前です。現在,このオプションはフォルダ全体の単位でしかエクスポート出来ません。通常このコマンドは -projectPath 引数を使って使用する必要があります。
-nographics (Windows only) バッチモードで実行するとき,グラフィックス デバイスは一切初期化しないで下さい。これにより自動化されたワークフローをGPUがないマシンで実行出来るようになります(自動化されたワークフローは,ウィンドウにフォーカスがあるときのみ機能し,そうでない場合はシミュレートされた入力コマンドを送信出来ません)。このオプションで生成されたスタンドアローン プレイヤーはグラフィックス機能がつきません。
-executeMethod <ClassName.MethodName> このstaticメソッドをUnityのスタート直後に実行,すなわちプロジェクトが開かれて,オプションにあたるアセットサーバーの更新が行われた直後です。これにより継続的インテグレーション,ユニットテストの実施,ビルド作成,データ準備等々に使用出来ます。もしコマンドライン処理のエラー結果がほしい場合は,例外を投げてUnityが戻り値 1 で終了するか, EditorApplication.Exit をコールしてゼロ以外の戻り値のコードとします。もし引数を渡したい場合コマンドラインに追加してSystem.Environment.GetCommandLineArgs を使用して取得します。

-executeMethod を使用するためには Editorフォルダにスクリプトがありクラスに 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, ...);
}


使用例

Unityをバッチモードで実行し,MyEditorScript.MyMethod メソッドを実行し,完了時に終了します。

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

Unityをバッチモードで実行します。与えられたプロジェクトパスを使用してasset serverから更新します。全てのアセットがダウンロードしasset serverからインポートされた後に与えられたメソッドを実行します。メソッド実行が完了した後,Unityを自動的に終了します。

/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:

-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.
-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-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-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.
-force-d3d11 (Windows only) Make the game use Direct3D 11 for rendering.
-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.
-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.
-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.
-popupwindow The window will be created as a a pop-up window (without a frame).
-screen-fullscreen Overrides the default fullscreen state. This must be 0 or 1.
-screen-height Overrides the default screen height. This must be an integer from a supported resolution.
-screen-width Overrides the default screen width. This must be an integer from a supported resolution.
-screen-quality Overrides the default screen quality. Example usage would be: /path/to/myGame -screen-quality Beautiful
-show-screen-selector Forces the screen selector dialog to be shown.
-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.
-parentHWND <HWND> (Windows only) Embeds Windows Standalone application into another application, you have to pass parent application’s window handle to Windows Standalone application. See this example EmbeddedWindow.zip for more information.

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 ストア : コマンドライン引数

Windows ストア アプリはデフォルトでコマンドライン引数を受付しないため,渡すためには App.xaml.cs/cpp または App.cs/cpp から特別な関数を呼び出しする必要があります。例えば,

appCallbacks.AddCommandLineArg("-nolog");

appCallbacks.Initialize*() 関数の前に呼び出しする必要があります。

-nolog UnityPlayer.log を生成しない。
-force-driver-type-warp DirectX 11.0 WARP を強制(詳細については http://msdn.microsoft.com/en-us/library/gg615082.aspx
-force-gfx-direct シングルスレッド レンダリングを強制。
-force-d3d11-no-singlethreaded DirectX 11.0 を D3D11_CREATE_DEVICE_SINGLETHREADED フラグなしで作成するように強制。
-force-feature-level–9–1 DirectX 11.0 機能レベル 9.1 を強制
-force-feature-level–9–2 DirectX 11.0 機能レベル 9.2 を強制
-force-feature-level–9–3 DirectX 11.0 機能レベル 9.3 を強制
-force-feature-level–10–0 DirectX 11.0 機能レベル 10.0 を強制
-force-feature-level–10–1 DirectX 11.0 機能レベル 10.1 を強制
-force-feature-level–11–0 DirectX 11.0 機能レベル 11.0 を強制
ストリーミングアセット
起動時エディタスクリプト実行