Version: 2019.1 (switch to 2018.3 or 2017.4)
LanguageEnglish
  • C#

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

Obsolete public static bool SwitchActiveBuildTarget(BuildTarget target);
public static bool SwitchActiveBuildTarget(BuildTargetGroup targetGroup, BuildTarget target);

Parameters

targetTarget build platform.
targetGroupBuild target group.

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.

When you change the currently active build target, this function reimports Assets that are affected by the current platform setting, and then returns. All script files are compiled on the next editor update. To have scripts compile before the Assets are reimported, see SwitchActiveBuildTargetAsync.

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.

using UnityEditor;

public class SwitchPlatformExample { [MenuItem("Example/Switch Platform")] public static void PerformSwitch() { // Switch to Windows standalone build. EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows); } }

Did you find this page useful? Please give it a rating: