Add this attribute to a method to get a callback when Unity processes a scene during a build.
PostProcessSceneAttribute is the attribute-based form of the IProcessSceneWithReport callback. Unity tracks and invokes both together, in callback order, with the same behavior. Use IProcessSceneWithReport for new code, because its OnProcessScene method receives the scene being processed and the BuildReport, while a PostProcessSceneAttribute method takes no parameters.
Unity invokes this callback during Player, AssetBundle, and content directory builds, and also when entering Play mode as a scene is loaded, for example when SceneManager.LoadScene is called.
PostProcessSceneAttribute has an option to provide an order index for the callback, starting at 0. This is useful if you have more than one PostProcessSceneAttribute or IProcessSceneWithReport callback and you want them called in a certain order. Callbacks are called in order, starting at zero.
Note: If there are no new changes to the scene since the previous Player build, Unity doesn't rebuild the scene but uses cached Player data instead. In this case the PostProcessSceneAttribute callback is not called. To ensure an unchanged scene rebuilds, you can either modify the scene or clear the build cache with BuildOptions.CleanBuildCache. Using EditorSceneManager.MarkSceneDirty alone is not sufficient to trigger the callback.
Additional resources: IProcessSceneWithReport, Use build callbacks, Incremental Build Pipeline
// C# example: // Automatically creates a game object with a primitive mesh renderer and appropriate collider. using UnityEngine; using UnityEditor; using UnityEditor.Callbacks;
public class MyScenePostprocessor { [PostProcessSceneAttribute (2)] public static void OnPostprocessScene() { GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = new Vector3(0.0f, 0.5f, 0.0f); } }