PostProcessSceneAttribute
Add this attribute to a method to get a callback when Unity processes a scene during a build.
Read time 4 minutesLast updated 6 days ago
Definition
- Type: Class
- Namespace: UnityEditor.Callbacks
- Assembly: UnityEditor.CoreModule
- Inherits from: CallbackOrderAttribute
public sealed class PostProcessSceneAttribute : CallbackOrderAttribute
Remarks
PostProcessSceneAttributeOnProcessScenePostProcessSceneAttributeUnity 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.
PostProcessSceneAttributePostProcessSceneAttributeNote: 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.
PostProcessSceneAttributeExamples
// 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); }}