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
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Multi-Scene-Editing interfering with 5.2 behaviour

Discussion in '5.3 Beta' started by Capn_Andy, Nov 26, 2015.

  1. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
    I have a bit of an abnormal setup, and I'm not sure if this is a bug or just "the new way that things work" and I should change my ways. Advice on transitioning to 5.3 (even if that just means "wait for a bugfix!") would be appreciated! (Bug report also submitted pointing to this thread)

    All was working well in 5.2; currently on 5.3.0f1

    The upgrade guide says that EditorApplication.OpenSceneAdditive is now deprecated, which we used heavily. In our project, we use scenes to mock up levels, and use an editor script to iterate through them - save out the relevant details in our own datafile format - and stow them in a Resources folder. We don't use the scenes in the built project and as such they are not marked for inclusion in the Build Settings.

    Our workflow is:
    1. Open a special "save all levels" scene.
    2. Hit Play.
    3. A special play-mode script that uses editor functions begins firing. Source posted below, but in english:

      This script first uses LoadAllAssetsAtPath to get a list of all the scenes in a particular location. It then (in 5.2) used OpenSceneAdditive to add in our mocked up gameObjects; we do some heavy processing on them with various in-game (not editor) scripts, and then we write a dataFile to a Resources folder. This process necessitates that it runs while in Play Mode. This has the side effect of me seeing a really pretty lightshow as all our gameobjects resize and move about in the editor window while this process happens.

      The script then loops to the next available level scene for processing, where all of our problems now occur. ;)

      After the script successfully dumps all our resource files, it automatically terminates Play mode to signal that it has completed it's processing.

    Here's my attempts at replacing the deprecated function:
    • EditorSceneManager.OpenScene(path, OpenSceneMode.Additive);
      This seems to be the intended replacement for the function, but produces the following error:

      An abnormal situation has occurred: the PlayerLoop internal function has been called recursively. Please contact Customer Support with a sample project so that we can reproduce the problem and troubleshoot it.
      UnityEditor.SceneManagement.EditorSceneManager:OpenScene(String, OpenSceneMode)


      Interestingly, this halts execution of play mode but leaves the editor "play" button depressed. I hit the "pause" button to reset the visual state of the editor, but things are clearly unstable here.

    • EditorSceneManager.OpenScene(path, OpenSceneMode.Single);
      Produces the same result as above.

    • EditorSceneManager.OpenScene(path, OpenSceneMode.AdditiveWithoutLoading);
      This seems to run fine - my scripts all operate as expected in the 5.2 fashion - but obviously the game objects haven't loaded and our processing doesn't work. The exported level files are understandably blank, and I don't see the pretty juggling of gameobjects in the editor window - it whips by really fast and says "success!" after nothing's been done. ;)

    • EditorSceneManager.LoadScene(path, LoadSceneMode.Additive);
      The LoadScene function seems to be reserved for scenes that are included in build settings; it produces the following error:

      Scene '[scene name]' (-1) couldn't be loaded because it has not been added to the build
      To add a scene to the build settings use the menu File->Build Settings...
      UnityEngine.SceneManagement.SceneManager:LoadScene(String, LoadSceneMode)
    • SceneManager.LoadScene(path, LoadSceneMode.Additive);
      Same as above - the non-editor version of the SceneManager cannot load scenes not included in Build Settings.
    Here's the (simplified) version of our processing script:

    Code (CSharp):
    1.     IEnumerator Start() {
    2.         UnityEngine.Object[] scenes;
    3.         scenes = LoadAllAssetsAtPath("Assets/Scenes/Levels");
    4.    
    5.         yield return 0; // wait for current scene to setup.
    6.    
    7.         for (int i = 0; i < scenes.Length; i++) {
    8.             string levelName;
    9.             string path = AssetDatabase.GetAssetPath(scenes[i]);
    10.             levelName = Path.GetFileNameWithoutExtension(path);
    11.            
    12.                 Debug.Log ("Loading: "+path);
    13. //                EditorSceneManager.OpenScene(path, OpenSceneMode.Additive);
    14. //                EditorSceneManager.OpenScene(path, OpenSceneMode.Single);
    15. //                EditorSceneManager.OpenScene(path, OpenSceneMode.AdditiveWithoutLoading);
    16. //                EditorSceneManager.LoadScene(path, LoadSceneMode.Additive);
    17.             SceneManager.LoadScene(path, LoadSceneMode.Additive);
    18.        
    19.             SaveEditorLevelToFile(levelName);
    20.         }
    21.    
    22.         // Editor does weird hangy things if we end it too quickly
    23.         yield return new WaitForSeconds(0.5f);
    24.         Debug.Log ("Done.");
    25.         EditorApplication.isPlaying = false;
    26.         AssetDatabase.Refresh();
    27.     }
    28.  
    (you can see the commented out attempts as listed above).
     
    Last edited: Nov 26, 2015
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    Why not just add the scenes to the Build Settings, and then have a build script (i.e. an editor script that calls BuildPipeline.BuildPlayer) that builds your game with the 'real' scenes you want to include in the build?
     
  3. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
    I suppose we could do that too; my biggest concern there is a less knowledgable person on the team not knowing to trigger this special build script and building the "wrong thing".

    I've written a workaround that uses EditorPrefs to store variables and iterate through each scene individually - manually starting and stopping the editor for each level. It's 100x slower than the script posted above but at least the behaviour is somewhat identical to 5.2...
     
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    Well, if you want to keep the Build Settings window itself 'safe', perhaps you could automatically set up and restore the scene list via the EditorBuildSettings.scenes API.