| Parameter | Description |
|---|---|
| scene | The current scene being processed. |
| report | A report containing information about the current build. When this callback is invoked for scene loading during Play mode, this parameter is null. |
Implement this method to receive a callback for each scene during the build.
Unity invokes this callback during Player, AssetBundle, and content directory builds, and also when a scene is loaded while in Play mode. Use BuildPipeline.isBuildingPlayer to determine in which context the callback is called.
This callback supports editing the provided scene to prepare it for a Player build or entering Play mode, and reading assets. For example, you can add or remove references to project assets in that scene.
This callback doesn't support modifying the state of other assets, creating new assets, or deleting assets. Use it to modify only the provided scene.
Don't access the build history from this callback. For content directory builds this callback can run in a separate worker process where BuildHistory is not available.
To fail the build from this callback, throw a BuildFailedException. It reports a clear message without a call stack and fails the build whether or not the build uses strict mode. A logged error, such as from Debug.LogError, fails the build only when the build uses strict mode (BuildOptions.StrictMode, BuildAssetBundleOptions.StrictMode, or BuildContentOptions.FailBuildWhenErrorsLogged).
Keep implementations deterministic. Avoid random values, timestamps, or external changing data sources. For more information, refer to Deterministic builds.
Use BuildPipelineContext.DependOnAsset and BuildPipelineContext.DependOnPath to add explicit dependencies to assets used during your scene modifications.
Apply BuildCallbackVersionAttribute to callback types and increment the version whenever the callback logic changes to help Unity invalidate cached scene processing results when needed.
For more information about build callbacks, refer to Use build callbacks.
Additional resources: BuildPipeline.BuildPlayer, BuildPipeline.BuildAssetBundles, BuildPipeline.BuildContentDirectory, BuildCallbackVersionAttribute, BuildPipelineContext
using UnityEditor; using UnityEditor.Build; using UnityEditor.Build.Reporting; using UnityEngine; [BuildCallbackVersion(1)] class MyCustomBuildProcessor : IProcessSceneWithReport { public int callbackOrder { get { return 0; } } public void OnProcessScene(UnityEngine.SceneManagement.Scene scene, BuildReport report) { Debug.Log("MyCustomBuildProcessor.OnProcessScene " + scene.name); } }