# IBuildProfilePostprocessBuild

> Implement this interface to define a callback that you can attach to a build profile. Unity invokes this callback after completing a build with this profile.

## Definition

* **Type:** Interface
* **Namespace:** [UnityEditor.Build.Profile](/engine/7000.0/script-reference/unityeditor/build/profile.md)
* **Assembly:** UnityEditor.CoreModule

```csharp
public interface IBuildProfilePostprocessBuild
```

## Remarks

This interface is the per-profile equivalent of [IPostprocessBuildWithContext](/engine/7000.0/script-reference/unityeditor/build/ipostprocessbuildwithcontext.md). An [IPostprocessBuildWithContext](/engine/7000.0/script-reference/unityeditor/build/ipostprocessbuildwithcontext.md) callback runs for every build. An `IBuildProfilePostprocessBuild` callback runs only when the build profile it's attached to is the active build profile. For more information, refer to [BuildProfile.GetActiveBuildProfile](/engine/7000.0/script-reference/unityeditor/build/profile/buildprofile/getactivebuildprofile.md). Unity doesn't invoke these callbacks for builds that target a classic platform, because these builds have no active build profile.

Like [IPostprocessBuildWithContext](/engine/7000.0/script-reference/unityeditor/build/ipostprocessbuildwithcontext.md), these callbacks run for player, AssetBundle, and content directory builds. They also run when the build fails or is canceled. To act only on some builds, check [BuildCallbackContext.IsPlayerBuild](/engine/7000.0/script-reference/unityeditor/build/buildcallbackcontext/isplayerbuild.md) or the result in [BuildCallbackContext.Report](/engine/7000.0/script-reference/unityeditor/build/buildcallbackcontext/report.md).

Implement the interface on a serializable class. The class doesn't need to derive from [ScriptableObject](/engine/7000.0/script-reference/unityengine/scriptableobject.md). To attach callbacks to a build profile, set [BuildProfilePostprocessBuild.callbacks](/engine/7000.0/script-reference/unityeditor/build/profile/buildprofilepostprocessbuild/callbacks.md) on the [BuildProfilePostprocessBuild](/engine/7000.0/script-reference/unityeditor/build/profile/buildprofilepostprocessbuild.md) component of the profile.  Unity saves the callback instances, including their serialized fields, with the build profile.

The callbacks attached to a profile run as one group, in the order of the [BuildProfilePostprocessBuild.callbacks](/engine/7000.0/script-reference/unityeditor/build/profile/buildprofilepostprocessbuild/callbacks.md) array, starting at index 0. To change the order, reorder the callbacks in the profile's **Post-process Build** section, or assign a reordered array. The group runs at the same point as an [IPostprocessBuildWithContext](/engine/7000.0/script-reference/unityeditor/build/ipostprocessbuildwithcontext.md) callback with a `callbackOrder` of `int.MaxValue`. It runs after all [IPostprocessBuildWithReport](/engine/7000.0/script-reference/unityeditor/build/ipostprocessbuildwithreport.md) callbacks, and after [IPostprocessBuildWithContext](/engine/7000.0/script-reference/unityeditor/build/ipostprocessbuildwithcontext.md) callbacks with a lower order. Unity doesn't define the order relative to other [IPostprocessBuildWithContext](/engine/7000.0/script-reference/unityeditor/build/ipostprocessbuildwithcontext.md) callbacks that also use `int.MaxValue`.

## Examples

```csharp
// Defines a post-build callback and a menu item that attaches it to a build profile.
// Save this script in an Editor folder and set k_ProfilePath to the path of your build profile.
using System;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Profile;
using UnityEngine;

[Serializable]
class MyProfilePostprocessBuild : IBuildProfilePostprocessBuild
{
    public void OnPostprocessBuild(BuildCallbackContext ctx)
    {
        Debug.Log($"Built with this profile at {ctx.Report.summary.outputPath}");
    }
}

static class AttachProfilePostprocessBuild
{
    const string k_ProfilePath = "Assets/Settings/Build Profiles/MyProfile.asset";

    [MenuItem("Tools/Attach Post-build Callback")]
    static void Attach()
    {
        var profile = AssetDatabase.LoadAssetAtPath<BuildProfile>(k_ProfilePath);

        // A build profile holds one component of each type, so reuse the component if it exists.
        var component = profile.GetComponent<BuildProfilePostprocessBuild>();
        if (component == null)
        {
            component = ScriptableObject.CreateInstance<BuildProfilePostprocessBuild>();
            profile.AddComponent(component);
        }

        // Assigning the array replaces any callbacks already attached.
        component.callbacks = new IBuildProfilePostprocessBuild[] { new MyProfilePostprocessBuild() };

        // Mark the component dirty so the change is saved with the profile.
        EditorUtility.SetDirty(component);
        AssetDatabase.SaveAssetIfDirty(profile);
    }
}
```

## Methods

| Method                                                                                                                              | Description                                                                    |
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [OnPostprocessBuild](/engine/7000.0/script-reference/unityeditor/build/profile/ibuildprofilepostprocessbuild/onpostprocessbuild.md) | Called after a build that used the build profile this callback is attached to. |
