Editor Script: Build for multiple platforms at once.

I have an application that exists to be deployed on multiple different devices. One is an android tablet, the others are windows standalones but need to have different player settings.

Here’s a snippet: (This exists in a function that takes in a enum type to decide how to switch. I can verify this function gets called and it does get into the correct cases:

switch (mode)
{
      case UserMode.Desktop:
           path="Builds/Desktop/SharedDesktop.exe";
           PlayerSettings.defaultIsFullScreen = false;
           PlayerSettings.defaultScreenWidth = 1600;
           PlayerSettings.defaultScreenHeight = 900;
           PlayerSettings.runInBackground = true;
           PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.HiddenByDefault;
           if (all) option = BuildOptions.None;
           else option = BuildOptions.ShowBuiltPlayer;
           EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.StandaloneWindows);
           BuildPipeline.BuildPlayer(levels, path, BuildTarget.StandaloneWindows, option);
                    
           break;

      case UserMode.Tablet:
           path = "Builds/Tablet/SharedTablet.apk";
                   
           EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.Android);
           BuildPipeline.BuildPlayer(levels, path, BuildTarget.Android, BuildOptions.None);
                 
           break;

    case UserMode.Laptop:
         path = "Builds/Laptop/SharedLaptop.exe";
         PlayerSettings.defaultIsFullScreen = true;
         PlayerSettings.defaultScreenWidth = 1280;
         PlayerSettings.defaultScreenHeight = 800;
         PlayerSettings.runInBackground = true;
         PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.HiddenByDefault;
    
         if (all) option = BuildOptions.None;
         else option = BuildOptions.ShowBuiltPlayer;

         EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.StandaloneWindows);
         BuildPipeline.BuildPlayer(levels, path, BuildTarget.StandaloneWindows, option);
                    
         break;
}

Unfortunately, this doesn’t work completely. I do end up with multiple builds made, but they all use the same player settings. Is there a trick to make BuildPipeline use the settings I’ve set. Or do I have to update the player settings somehow? The documentation on this is vague and unhelpful.

I think you should call SwitchActiveBuildTarget first, before you change any settings…