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.
Read time 2 minutesLast updated 8 days ago
Definition
- Type: Interface
- Namespace: UnityEditor.Build.Profile
- Assembly: UnityEditor.CoreModule
public interface IBuildProfilePostprocessBuild
Remarks
This interface is the per-profile equivalent of IPostprocessBuildWithContext. An IPostprocessBuildWithContext callback runs for every build. An callback runs only when the build profile it's attached to is the active build profile. For more information, refer to BuildProfile.GetActiveBuildProfile. Unity doesn't invoke these callbacks for builds that target a classic platform, because these builds have no active build profile.
IBuildProfilePostprocessBuildLike IPostprocessBuildWithContext, 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 or the result in BuildCallbackContext.Report.
Implement the interface on a serializable class. The class doesn't need to derive from ScriptableObject. To attach callbacks to a build profile, set BuildProfilePostprocessBuild.callbacks on the BuildProfilePostprocessBuild 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 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 callback with a of . It runs after all IPostprocessBuildWithReport callbacks, and after IPostprocessBuildWithContext callbacks with a lower order. Unity doesn't define the order relative to other IPostprocessBuildWithContext callbacks that also use .
callbackOrderint.MaxValueint.MaxValueExamples
// 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 | Called after a build that used the build profile this callback is attached to. |