Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

EditorSceneManager.sceneLoaded isn't working

Discussion in '5.4 Beta' started by fastgamedev, Mar 22, 2016.

  1. fastgamedev

    fastgamedev

    Joined:
    Mar 27, 2014
    Posts:
    79
    I can't get sceneLoaded delegates to work. The code below does not work when scenes are loaded either in Edit mode or in Play mode. Is this a bug or am I missing the correct format?


    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4. using UnityEditor.SceneManagement;
    5. using UnityEngine.SceneManagement;
    6.  
    7. [InitializeOnLoad]
    8. public class AddManagerScene {
    9.     static AddManagerScene() {
    10.         EditorSceneManager.sceneLoaded += OnSceneLoaded;
    11.         SceneManager.sceneLoaded += OnSceneLoaded;
    12.     }
    13.  
    14.     static void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode) {
    15.         Debug.Log("OnSceneLoaded");
    16.     }
    17. }
    18.  
     
  2. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    219
    Hi,
    EditorSceneManager derives from SceneManager so it does not make sense to hook up twice to the 'sceneLoaded' event. EditorSceneManager events for edit mode scene events is coming later in the 5.4 beta cycle (e.g sceneOpened/Closed etc).
    Note that the SceneManager events only works in play mode. I tried your script on 5.4 b10 and it works a expected here: I get the "OnSceneLoaded" logged when loading scenes.
    If this is still not the case on your side then please submit a bug report with your project so we can take a closer look.
     
  3. fastgamedev

    fastgamedev

    Joined:
    Mar 27, 2014
    Posts:
    79
    Thank you, Mads.