facebook twitter hatena line email

Unity/Editor/コマンド実行

提供: 初心者エンジニアの簡易メモ
2021年8月10日 (火) 16:34時点におけるAdmin (トーク | 投稿記録)による版 (namespaceを使う場合)

移動: 案内検索

コマンド実行の対応方法

UnityEditorを使って、commandで実行

公式マニュアル:https://docs.unity3d.com/ja/2019.4/Manual/CommandLineArguments.html

サンプル

Assets/Scripts/Editor/MyEditorScript.cs

using UnityEditor;
using UnityEngine;
class MyEditorScript
{
    static void Exec()
    {
        Debug.Log("Build Start");
    }
}

コマンド実行

mac

/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod MyEditorScript.Exec

mac(unity hub)

/Applications/Unity/Hub/Editor/2019.4.26f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod MyEditorScript.Exec

参考:https://docs.unity3d.com/ja/2019.4/Manual/CommandLineArguments.html

ログ

mac

~/Library/Logs/Unity/Editor.log

注意:ログは、新規作成されるので、tail -f などで、確認する場合は、実行後に、tail実行しないと、確認できない。

project openエラーが出るとき

プロジェクトをGUIで開いているとエラーが出るので、閉じてからコマンド実行する

Aborting batchmode due to failure:
Fatal Error! It looks like another Unity instance is running with this project open.
Multiple Unity instances cannot open the same project.

compiler errorsが出るとき

ビルドが失敗してるので、プラットフォームが正しいかなど確認する。(GUI上での実行だと、スクリプトエラーが発生してるはず)

Aborting batchmode due to failure:
Scripts have compiler errors.

could not be found.が出る場合

以下エラーが出る場合

Aborting batchmode due to failure:
executeMethod method 'HogeMethod1' in class 'HogeClass1' could not be found.
Argument was -executeMethod HogeMethod1.HogeClass1

プロジェクトをGUIで開いている場合は、閉じる

コマンドオプション

  • -logFile:ログファイル
  • -projectPath:プロジェクトの場所
  • -quit:処理後自動終了
Unity -batchmode -quit -logFile /tmp/build.log -projectPath ~/unity/project1 -executeMethod MyEditorScript.Exec

参考:https://qiita.com/sango/items/474efb4c016a136c84ce

namespaceを使う場合

using UnityEditor;
using UnityEngine;
namespace Module1 {
    class MyEditorScript
    {
        static void Exec()
        {
            Debug.Log("Build Start");
        }
    }
}

以下でコマンド実行できる

/Applications/Unity/Hub/Editor/2019.4.26f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod Module1.MyEditorScript.Exec