PostProcessSceneAttribute
Add this attribute to a method to get a notification just after building the Scene.
Read time 4 minutesLast updated 5 days ago
Definition
- Type: Class
- Namespace: UnityEditor.Callbacks
- Assembly: UnityEditor.CoreModule
- Inherits from: CallbackOrderAttribute
public sealed class PostProcessSceneAttribute : CallbackOrderAttribute
Remarks
A method with this attribute will also get called when entering Playmode, when SceneManager.LoadScene is called.
PostProcessSceneAttributeNote: 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 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.
PostProcessSceneAttributeAdditional Resources: IProcessSceneWithReport, Incremental Build Pipeline
Examples
// 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); }}