Legacy Documentation: Version 5.5
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorUserBuildSettings.SwitchActiveBuildTarget

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

Submission failed

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

Close

Cancel

public static function SwitchActiveBuildTarget(target: BuildTarget): bool;
public static bool SwitchActiveBuildTarget(BuildTarget target);

Returns

bool True if the build target was successfully switched, false otherwise (for example, if license checks fail, files are missing, or if the user has cancelled the operation via the UI).

Description

Select a new build target to be active.

Has the same effect as changing the build target via the Build Player dialog in the editor.

Changing the currently active build target will recompile all script files for the new platform and will reimport assets that are affected by the current platform setting (textures with platform-specific settings, for example).

If the given target is a standalone target, calling SwitchActiveBuildTarget will also affect EditorUserBuildSettings.selectedStandaloneTarget.

Note: This method is not available when running the Editor in batch mode. This is because changing the build target requires recompiling script code for the given target which cannot be done while script code is executing (not a problem in in the editor as the operation is simply deferred but batch mode will immediately exit after having executed the designated script code). To set the build target to use in batch mode, use the buildTarget command-line switch.

#pragma strict
function Start() {
	// Switch to Windows standalone build.
	EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.StandaloneWindows);
}
using UnityEngine;
using UnityEditor;

public class ExampleClass : MonoBehaviour { void Start() { // Switch to Windows standalone build. EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.StandaloneWindows); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961