Legacy Documentation: Version 5.6 (Go to current version)
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 function BuildPlayer(buildPlayerOptions: BuildPlayerOptions): string;
public static string BuildPlayer(BuildPlayerOptions buildPlayerOptions);

Parameters

buildPlayerOptions Provide various options to control the behavior of BuildPipeline.BuildPlayer.

Returns

string An error message if an error occurred.

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.

#pragma strict
public class BuildPlayerExample extends MonoBehaviour {
	@MenuItem("Build/Build iOS")
	public static function MyBuild() {
		var buildPlayerOptions: BuildPlayerOptions = new BuildPlayerOptions();
		buildPlayerOptions.scenes = ["Assets/Scene1.unity", "Assets/Scene2.unity"];
		buildPlayerOptions.locationPathName = "iOSBuild";
		buildPlayerOptions.target = BuildTarget.iOS;
		buildPlayerOptions.options = BuildOptions.None;
		BuildPipeline.BuildPlayer(buildPlayerOptions);
	}
}
using UnityEditor;

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; BuildPipeline.BuildPlayer(buildPlayerOptions); } }

public static function BuildPlayer(levels: string[], locationPathName: string, target: BuildTarget, options: BuildOptions): string;
public static string BuildPlayer(string[] levels, string locationPathName, BuildTarget target, BuildOptions options);
public static function BuildPlayer(levels: EditorBuildSettingsScene[], locationPathName: string, target: BuildTarget, options: BuildOptions): string;
public static string BuildPlayer(EditorBuildSettingsScene[] levels, string locationPathName, BuildTarget target, BuildOptions options);

Parameters

levels The 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).
locationPathName The path where the application will be built.
target The BuildTarget to build.
options Additional BuildOptions, like whether to run the built player.

Returns

string An error message if an error occurred.

Description

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

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961