Search Unity

Change the default scene

Discussion in 'Editor & General Support' started by DaCookie, Jul 13, 2015.

  1. DaCookie

    DaCookie

    Joined:
    Nov 4, 2014
    Posts:
    44
    Hi everybody.

    My question is very simple : is it possible to change the default scene, and how ?

    What I call default scene is the scene loaded when you make a "New Scene", with a light and a camera.

    Thanks for your help :)
     
    adnanzmn97 likes this.
  2. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
    No, there is no templates for scenes. But you can duplicate existing scene in project view. I usually have couple scenes like temp and Level_clean, and i just duplicate one of those rather than creating new scene.
     
    Game_Taco and adnanzmn97 like this.
  3. DaCookie

    DaCookie

    Joined:
    Nov 4, 2014
    Posts:
    44
    Ok, thanks. Until now, I used to duplicate my scenes like you said, and it looks like I've to continue :/
     
  4. thedackattack

    thedackattack

    Joined:
    Jun 4, 2013
    Posts:
    7
    I was looking to do this and found a way around it. It's a bit hacky, but you can create a static class that gets initialized when the editor loads, get a callback when the hierarchy changes and search the hierarchy to see if it matches the default scene. From there you can clear the scene and load assets from whatever scene you want in.

    Code (CSharp):
    1. [InitializeOnLoad]
    2. public class MyScenePostprocessor
    3. {
    4.     static MyScenePostprocessor()
    5.     {
    6.         EditorApplication.hierarchyWindowChanged += ExampleCallback;
    7.     }
    8.  
    9.     static void ExampleCallback()
    10.     {
    11.         List<GameObject> sceneObjects = new List<GameObject>(GameObject.FindObjectsOfType<GameObject>());
    12.  
    13.         // Does it match the default scene exactly?
    14.         if (sceneObjects.Count == 2 && sceneObjects.Find(go => go.name == "Main Camera") && sceneObjects.Find(go => go.name == "Directional Light"))
    15.         {
    16.             string defaultScenePath = System.IO.Path.Combine(Application.dataPath, "Scenes/DefaultSceneOverride.unity");
    17.             if (System.IO.File.Exists(defaultScenePath))
    18.             {
    19.                 Debug.Log("Detected default scene - replacing with DefaultSceneOverride");
    20.                 EditorApplication.NewEmptyScene();
    21.                 EditorApplication.OpenSceneAdditive(defaultScenePath);
    22.             }
    23.         }
    24.     }
    25. }
     
    Game_Taco, Pacosmico and Baste like this.
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    That is a neat little hack. I like it.
     
  6. Pacosmico

    Pacosmico

    Joined:
    Jan 16, 2014
    Posts:
    14
  7. leandic

    leandic

    Joined:
    Sep 3, 2014
    Posts:
    7
    Here's an example of how to modify the default scene.

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.SceneManagement;
    3. using UnityEngine;
    4. using UnityEngine.Rendering;
    5. using UnityEngine.SceneManagement;
    6.  
    7. [InitializeOnLoad]
    8. public class NewSceneSetup : Editor
    9. {
    10.     static NewSceneSetup()
    11.     {
    12.         EditorSceneManager.newSceneCreated += OnNewScene;
    13.     }
    14.  
    15.     private static void OnNewScene(Scene scene, UnityEditor.SceneManagement.NewSceneSetup setup, NewSceneMode mode)
    16.     {
    17.         Camera.main.backgroundColor = Color.black;
    18.         Camera.main.clearFlags = CameraClearFlags.SolidColor;
    19.         Camera.main.transform.position = Vector3.zero;
    20.  
    21.         var light = FindObjectOfType<Light>();
    22.         if (light != null)
    23.         {
    24.             DestroyImmediate(light.gameObject);
    25.         }
    26.  
    27.         RenderSettings.skybox = null;
    28.         RenderSettings.ambientIntensity = 0f;
    29.         RenderSettings.ambientLight = Color.black;
    30.         RenderSettings.ambientMode = AmbientMode.Flat;
    31.         Lightmapping.bakedGI = false;
    32.     }
    33. }
     
    joelyusj likes this.