Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


SwitchActiveBuildTargetAsync(BuildTargetGroup, BuildTarget)

Select a new build target to be active during the next Editor update.
Read time 1 minuteLast updated 6 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor
public static bool SwitchActiveBuildTargetAsync(BuildTargetGroup targetGroup, BuildTarget target)

Parameters

targetGroup

Build target group.

Target build platform.

Returns

Type

Description

boolTrue 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).

Remarks

Changes the active build target to the specified build target during the next Editor update.
All script files and assets affected by the current platform settings are recompiled or reimported on the next Editor update when you change the active build target. For information on how to immediately import assets, refer to SwitchActiveBuildTarget.
If the given target is a standalone target, calling
SwitchActiveBuildTarget
also affects EditorUserBuildSettings.selectedStandaloneTarget.
This method isn't available when running the Editor in batch mode. Changing the build target requires recompiling script code for the given target, which can't be done while script code is executing. This isn't a problem in the Editor, because the operation is deferred to the next Editor update. However, in batch mode the Editor stops after executing the designated script code, so deferring the operation isn't possible. To set the build target to use in batch mode, use the buildtarget command-line argument.

Examples

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); }}