# BuildPlayer

> Builds a player from a specific build profile.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.3/script-reference/unityeditor.md)
* **Assembly:** UnityEditor

## BuildPlayer(BuildPlayerWithProfileOptions)

Builds a player from a specific build profile.

```csharp
public static BuildReport BuildPlayer(BuildPlayerWithProfileOptions buildPlayerWithProfileOptions)
```

### Parameters

**** (\[BuildPlayerWithProfileOptions]\(/engine/6000.3/script-reference/unityeditor/buildplayerwithprofileoptions)): Provide various options to control the behavior of [BuildPipeline.BuildPlayer](/engine/6000.3/script-reference/unityeditor/buildpipeline/buildplayer.md) when using a [build profile](/engine/6000.3/script-reference/unityeditor/build/profile/buildprofile.md).

### Returns

| Type                                                                                      | Description                                                                                                                              |
| ----------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| [BuildReport](/engine/6000.3/script-reference/unityeditor/build/reporting/buildreport.md) | A [BuildReport](/engine/6000.3/script-reference/unityeditor/build/reporting/buildreport.md) object containing build process information. |

### Examples

```csharp
using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEditor.Build.Profile;
using UnityEngine;

public class BuildPlayerWithBuildProfileExample
{
    [MenuItem("Build/Build iOS Demo")]
    public static void MyBuild()
    {
        BuildProfile buildProfile = AssetDatabase.LoadAssetAtPath<BuildProfile>("Assets/Settings/Build Profiles/iOSDemo.asset");
        BuildPlayerWithProfileOptions options = new BuildPlayerWithProfileOptions()
        {
            buildProfile = buildProfile,
            locationPathName = "iOSDemoBuild",
            options = BuildOptions.None,
        };

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

        // Output the build size or a failure depending on BuildPlayer.
        if (summary.result == BuildResult.Succeeded)
        {
            Debug.Log("Build succeeded: " + summary.totalSize + " bytes");
        }

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

## BuildPlayer(EditorBuildSettingsScene\[], string, BuildTarget, BuildOptions)

Builds a Player. These overloads are still supported, but will be replaced. Please use BuildPlayer([BuildPlayerOptions](/engine/6000.3/script-reference/unityeditor/buildplayeroptions.md) buildPlayerOptions) and BuildPlayer([BuildPlayerWithProfileOptions](/engine/6000.3/script-reference/unityeditor/buildplayerwithprofileoptions.md) buildPlayerWithProfileOptions) instead.

```csharp
public static BuildReport BuildPlayer(EditorBuildSettingsScene[] levels, string locationPathName, BuildTarget target, BuildOptions options)
```

### Parameters

**** (\[EditorBuildSettingsScene\[]]\(/engine/6000.3/script-reference/unityeditor/editorbuildsettingsscene)): The scenes to include in the build. If empty, the build includes only the current open scene. Paths are relative to the project folder, for example `Assets/MyLevels/MyScene.unity`.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The path where the application will be built. For information on the platform extensions to include in the path, refer to [Build path requirements for target platforms](/engine/6000.3/manual/building-and-publishing/build-customize-build-pipeline/build-path-requirements.md).**** (\[BuildTarget]\(/engine/6000.3/script-reference/unityeditor/buildtarget)): The [BuildTarget](/engine/6000.3/script-reference/unityeditor/buildtarget.md) to build.**** (\[BuildOptions]\(/engine/6000.3/script-reference/unityeditor/buildoptions)): Additional [BuildOptions](/engine/6000.3/script-reference/unityeditor/buildoptions.md), like whether to run the built player.

### Returns

| Type                                                                                      | Description                                                                                                                              |
| ----------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| [BuildReport](/engine/6000.3/script-reference/unityeditor/build/reporting/buildreport.md) | A [BuildReport](/engine/6000.3/script-reference/unityeditor/build/reporting/buildreport.md) object containing build process information. |

## BuildPlayer(string\[], string, BuildTarget, BuildOptions)

Builds a Player. These overloads are still supported, but will be replaced. Please use BuildPlayer([BuildPlayerOptions](/engine/6000.3/script-reference/unityeditor/buildplayeroptions.md) buildPlayerOptions) and BuildPlayer([BuildPlayerWithProfileOptions](/engine/6000.3/script-reference/unityeditor/buildplayerwithprofileoptions.md) buildPlayerWithProfileOptions) instead.

```csharp
public static BuildReport BuildPlayer(string[] levels, string locationPathName, BuildTarget target, BuildOptions options)
```

### Parameters

**** (\[string\[]]\(https\://learn.microsoft.com/dotnet/api/system.string)): The scenes to include in the build. If empty, the build includes only the current open scene. Paths are relative to the project folder, for example `Assets/MyLevels/MyScene.unity`.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The path where the application will be built. For information on the platform extensions to include in the path, refer to [Build path requirements for target platforms](/engine/6000.3/manual/building-and-publishing/build-customize-build-pipeline/build-path-requirements.md).**** (\[BuildTarget]\(/engine/6000.3/script-reference/unityeditor/buildtarget)): The [BuildTarget](/engine/6000.3/script-reference/unityeditor/buildtarget.md) to build.**** (\[BuildOptions]\(/engine/6000.3/script-reference/unityeditor/buildoptions)): Additional [BuildOptions](/engine/6000.3/script-reference/unityeditor/buildoptions.md), like whether to run the built player.

### Returns

| Type                                                                                      | Description                                                                                                                              |
| ----------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| [BuildReport](/engine/6000.3/script-reference/unityeditor/build/reporting/buildreport.md) | A [BuildReport](/engine/6000.3/script-reference/unityeditor/build/reporting/buildreport.md) object containing build process information. |

## BuildPlayer(BuildPlayerOptions)

Builds a player.

```csharp
public static BuildReport BuildPlayer(BuildPlayerOptions buildPlayerOptions)
```

### Parameters

**** (\[BuildPlayerOptions]\(/engine/6000.3/script-reference/unityeditor/buildplayeroptions)): Provide various options to control the behavior of [BuildPipeline.BuildPlayer](/engine/6000.3/script-reference/unityeditor/buildpipeline/buildplayer.md).

### Returns

| Type                                                                                      | Description                                                                                                                              |
| ----------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| [BuildReport](/engine/6000.3/script-reference/unityeditor/build/reporting/buildreport.md) | A [BuildReport](/engine/6000.3/script-reference/unityeditor/build/reporting/buildreport.md) object containing build process information. |

### Remarks

Use this function to programatically create a build of your project.

Calling this method will invalidate any variables in the editor script that reference GameObjects, so they will need to be reacquired after the call.

Scripts can run at strategic points during the build by implementing one of the supported callback interfaces, for example [BuildPlayerProcessor](/engine/6000.3/script-reference/unityeditor/build/buildplayerprocessor.md), [IPreprocessBuildWithContext](/engine/6000.3/script-reference/unityeditor/build/ipreprocessbuildwithcontext.md), [IProcessSceneWithReport](/engine/6000.3/script-reference/unityeditor/build/iprocessscenewithreport.md) and [IPostprocessBuildWithContext](/engine/6000.3/script-reference/unityeditor/build/ipostprocessbuildwithcontext.md).

Note: Be aware that changes to [scripting symbols](/engine/6000.3/manual/scripting/compilation-and-code-reload/script-compilation/conditional-compilation/platform-dependent-compilation.md) only take effect at the next domain reload, when scripts are recompiled.

This means if you make changes to the defined scripting symbols via code using SetDefineSymbolsForGroup without a domain reload before calling this function, those changes won't take effect.

It also means that the built-in scripting symbols defined for the current active target platform (such as UNITY\_STANDALONE\_WIN, or UNITY\_ANDROID) remain in place even if you try to build for a different target platform, which can result in the wrong code being compiled into your build.

Additional Resources: [BuildPlayerWindow.DefaultBuildMethods.BuildPlayer](/engine/6000.3/script-reference/unityeditor/buildplayerwindow/defaultbuildmethods/buildplayer.md).

### Examples

```csharp
using UnityEditor;
using UnityEngine;
using UnityEditor.Build.Reporting;

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

public class BuildPlayerExample
{
    [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");
        }
    }
}
```
