Search Unity

[PostProcessScene]... but which scene?

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

  1. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    254
    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:
    254
    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:
    254
    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. }
     
    MaxEden, Baste, abegue and 2 others like this.