Why Doesn’t A Failed BuildPipeline.BuildPlayer Return An Error Code In The Command Line? (Unity)
- 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.
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.