Consider this C# script snippet used in Unity Editor to build a standalone PC/Mac application. What will be the output in the console after running this method?
using UnityEditor; using UnityEngine; public class BuildScript { public static void BuildGame() { string path = "Builds/MyGame.exe"; BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions(); buildPlayerOptions.scenes = new[] {"Assets/Scenes/Main.unity"}; buildPlayerOptions.locationPathName = path; buildPlayerOptions.target = BuildTarget.StandaloneWindows64; buildPlayerOptions.options = BuildOptions.None; var report = BuildPipeline.BuildPlayer(buildPlayerOptions); if (report.summary.result == UnityEditor.Build.Reporting.BuildResult.Succeeded) { Debug.Log("Build succeeded: " + report.summary.totalSize + " bytes"); } else { Debug.Log("Build failed"); } } }
Think about what BuildPipeline.BuildPlayer returns and what the summary.totalSize represents.
The BuildPipeline.BuildPlayer method returns a BuildReport object. If the build succeeds, the summary.result is Succeeded and totalSize is the size of the built player in bytes, which is a positive number. So the output will be "Build succeeded: [some positive number] bytes".
You want to create a standalone build for Mac OS using Unity. Which BuildTarget enum value should you use?
Mac standalone builds require a specific target for Mac OS.
For Mac standalone builds, Unity uses BuildTarget.StandaloneOSX. Windows builds use StandaloneWindows64. iOS and WebGL are for different platforms.
Look at this build script snippet. The build fails with an error about missing scenes. What is the cause?
BuildPlayerOptions options = new BuildPlayerOptions();
options.scenes = new string[] {"Assets/Scenes/Level1.unity", "Assets/Scenes/Level2.unity"};
options.locationPathName = "Builds/MyGame.exe";
options.target = BuildTarget.StandaloneWindows64;
BuildPipeline.BuildPlayer(options);Check if the scenes are included in the Unity build settings and if the paths are correct.
Unity requires scenes to be added to the build settings or referenced correctly. If the scene paths are wrong or not included in build settings, the build fails with missing scenes error.
Choose the correct way to set the build output path for a Mac standalone build in Unity.
Mac standalone builds produce an application bundle with a specific extension.
Mac standalone builds produce an application bundle with the .app extension. Using .exe is for Windows, and .dmg is a disk image, not the build output.
Given this build script snippet, how many scenes will be included in the final build?
string[] scenes = new string[] {
"Assets/Scenes/Main.unity",
"Assets/Scenes/Intro.unity",
"Assets/Scenes/Level1.unity"
};
BuildPlayerOptions options = new BuildPlayerOptions();
options.scenes = scenes;
options.locationPathName = "Builds/GameBuild.exe";
options.target = BuildTarget.StandaloneWindows64;
BuildPipeline.BuildPlayer(options);When you specify scenes explicitly in BuildPlayerOptions, those scenes are included regardless of build settings.
When you provide the scenes array explicitly in BuildPlayerOptions, Unity includes exactly those scenes in the build, ignoring the build settings scenes list.