Version: 2018.1 (switch to 2018.2 or 2017.4)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

BuildPipeline.BuildPlayer

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 method BuildPlayer(buildPlayerOptions: BuildPlayerOptions): Build.Reporting.BuildReport;
public static Build.Reporting.BuildReport BuildPlayer(BuildPlayerOptions buildPlayerOptions);

Parameters

buildPlayerOptionsProvide various options to control the behavior of BuildPipeline.BuildPlayer.

Returns

BuildReport A BuildReport giving build process information.

Description

Builds a player.

Use this function to programatically create a build of your project. Note that any references to GameObjects acquired in the editor script before the BuildPlayer call will be invalid after it and will need to be reacquired.

no example available in JavaScript
using UnityEditor;
using UnityEngine;
using UnityEditor.Build.Reporting;

// Output the build size or a failure depending on BuildPlayer.

public class BuildPlayerExample : MonoBehaviour { [MenuItem("Build/Build iOS")] public static void MyBuild() { BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions(); buildPlayerOptions.scenes = new[] { "Assets/Scene1.unity", "Assets/Scene2.unity" }; buildPlayerOptions.locationPathName = "iOSBuild"; buildPlayerOptions.target = BuildTarget.iOS; buildPlayerOptions.options = BuildOptions.None;

BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions); BuildSummary summary = report.summary;

if (summary.result == BuildResult.Succeeded) { Debug.Log("Build succeeded: " + summary.totalSize + " bytes"); }

if (summary.result == BuildResult.Failed) { Debug.Log("Build failed"); } } }

public static method BuildPlayer(levels: string[], locationPathName: string, target: BuildTarget, options: BuildOptions): Build.Reporting.BuildReport;
public static Build.Reporting.BuildReport BuildPlayer(string[] levels, string locationPathName, BuildTarget target, BuildOptions options);
public static method BuildPlayer(levels: EditorBuildSettingsScene[], locationPathName: string, target: BuildTarget, options: BuildOptions): Build.Reporting.BuildReport;
public static Build.Reporting.BuildReport BuildPlayer(EditorBuildSettingsScene[] levels, string locationPathName, BuildTarget target, BuildOptions options);

Parameters

levelsThe scenes to be included in the build. If empty, the currently open scene will be built. Paths are relative to the project folder (Assets/MyLevels/MyScene.unity).
locationPathNameThe path where the application will be built.
targetThe BuildTarget to build.
optionsAdditional BuildOptions, like whether to run the built player.

Returns

BuildReport An error message if an error occurred.

Description

Builds a player. These overloads are still supported, but will be replaced. Please use BuildPlayer (BuildPlayerOptions buildPlayerOptions) instead.

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