- Using -executeMethod and BuildPipeline.BuildPlayer fails when running Unity from the command line, and the exit code 0 (successful) is received where fail is expected.
When a build fails when using BuildPipeline.BuildPlayer, Unity will continue working on the method after BuildPipeline.BuildPlayer has completed. Once the entire method is run, Unity will stop returning the successful error code.
BuildPipeline.BuildPlayer returns a string - if this string is empty, the build was successful. The following code shows an example of reading the error and exiting Unity, sending the value 0 if the build was successful and 1 if it failed.
string error = BuildPipeline.BuildPlayer( levels, "iOS ", BuildTarget.iOS, BuildOptions.None ); if( string.IsNullOrEmpty( error ) ) EditorApplication.Exit( 0 ); else EditorApplication.Exit( 1 );
Note that when calling EditorApplication.Exit from script, -quit is not necessary to automatically exit the Editor once it is completed as the method will already exit the Editor before the end. If an exception is thrown or other errors occur, however, the Editor will remain open if -quit is not used.
For more information, consult the following documentation: