Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

[PostProcessScene]... but which scene?

Discussion in 'Editor & General Support' started by steinbitglis, May 5, 2021.

  1. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    251
    I have a method OnPostProcessScene where I want to add and remove some objects when playmode is entered, or when a player is being built.

    But I can not figure out which scene is being post processed.

    Code (CSharp):
    1.     [PostProcessScene]
    2.     public static void OnPostprocessScene() {
    3.         // Called once per scene, but the scene is unknown?
    4.     }
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
  3. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    251
    When I enter play mode and print during PostProcessScene, I get the same active scene printed six times, that's my problem.
     
    fffMalzbier likes this.
  4. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    251
    If anyone else runs into this issue, there is an alternative API that does seemingly exactly the same thing, but it includes the scene being processed, thankfully.
    https://docs.unity3d.com/ScriptReference/Build.IProcessSceneWithReport.OnProcessScene.html

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.Build;
    3. using UnityEditor.Build.Reporting;
    4. using UnityEngine;
    5.  
    6. class MyCustomBuildProcessor : IProcessSceneWithReport
    7. {
    8.     public int callbackOrder { get { return 0; } }
    9.     public void OnProcessScene(UnityEngine.SceneManagement.Scene scene, BuildReport report)
    10.     {
    11.         Debug.Log("MyCustomBuildProcessor.OnProcessScene " + scene.name);
    12.     }
    13. }