static BuildPlayerOptions GetBuildPlayerOptions( bool askForLocation = false, BuildPlayerOptions defaultOptions = new BuildPlayerOptions()) { // Fake BuildLocation path to prevent Unity exception var activeBuildTarget = EditorUserBuildSettings.activeBuildTarget; var buildLocation = EditorUserBuildSettings.GetBuildLocation(activeBuildTarget); // Making sure that current BuildLocation is valid, otherwise create new proper one. // New created location will be like: .../<ProjectRoot>/Builds/<BuildTarget> switch (InternalEditorUtility.BuildCanBeAppended(activeBuildTarget, buildLocation)) { case CanAppendBuild.No: case CanAppendBuild.Unsupported: var newBuildLocation = CombinePaths(DefaultBuildLocation, "build"); EditorUserBuildSettings.SetBuildLocation(activeBuildTarget, newBuildLocation); break; } // Get static internal "GetBuildPlayerOptionsInternal" method and invoke it var method = typeof(BuildPlayerWindow.DefaultBuildMethods).GetMethod( "GetBuildPlayerOptionsInternal", BindingFlags.NonPublic | BindingFlags.Static); return((BuildPlayerOptions)method.Invoke( null, new object[] { askForLocation, defaultOptions })); }