Version: 2019.2
LanguageEnglish
  • C#

EditorUserBuildSettings.SwitchActiveBuildTargetAsync

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 bool SwitchActiveBuildTargetAsync(BuildTargetGroup targetGroup, BuildTarget target);

Parameters

targetGroupTarget build platform.
targetBuild 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 during the next Editor update.

This function switches to the passed build target as the active build during the next Editor update. It has the same effect as changing the build target via the Build Player dialog in the Editor.

All script files and Assets that are affected by the current platform settings, are recompiled or reimported on the next Editor update when you change the currently active build target that this function returns. See SwitchActiveBuildTarget on how to immediately import Assets.

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

Note: This function is not available when running the Editor in batch mode because changing the build target requires recompiling script code for the given target which cannot be done while your script code is executing. This is not a problem in in the Editor as the operation is deferred. However, batch mode will immediately exit after having executed the designated script code. Use the buildTarget command-line switch to specify a build target from batch mode.

using UnityEngine;
using UnityEditor;
using UnityEditor.Build;

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

public int callbackOrder { get { return 0; } } public void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget newTarget) { Debug.Log("Active platform is now " + newTarget); } }