Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

AssetPostprocessor.OnProcessScene(Scene, SceneImportContext)

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Parameters

Parameter Description
scene The scene that Unity is processing.
sceneContext Additional context about the scene being processed.

Description

Implement this method to receive a callback for each scene loaded during a Player build or when the Editor is in Play mode.

Unity invokes this callback for each scene loaded during any Player build and when loading a scene in Play mode.

This callback supports editing the provided scene to change its content for the target Player build. 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, including creating or removing files in the project. Use it to modify only the provided scene.

Keep implementations deterministic. Avoid random values, timestamps, or external changing data sources. For more information, refer to Deterministic builds.

When changing the implementation, use AssetPostprocessor.GetVersion to increment your postprocessor value so the build process can pick up the changes on the next build.

Use AssetPostprocessor.context to register any dependency that would require an update on a subsequent build.

For more information about build callbacks, refer to Use build callbacks.

using UnityEditor;
using UnityEditor.Build.Content;
using UnityEngine;
using UnityEngine.SceneManagement;

// Logs a message for every scene Unity processes during a Player build or in Play mode. class MyCustomBuildProcessor : AssetPostprocessor { public override uint GetVersion() => 1;

public void OnProcessScene(Scene scene, SceneImportContext sceneContext) { Debug.Log("MyCustomBuildProcessor.OnProcessScene " + scene.name); } }