Search Unity

  1. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

Anyone know why "using UnityEditor.SceneMangement;" is preventing builds of my project?

Discussion in 'Scripting' started by Jeff-Berry, Jan 11, 2019.

  1. Jeff-Berry

    Jeff-Berry

    Joined:
    Aug 31, 2012
    Posts:
    99
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3. using UnityEditor.SceneManagement;
    4.  
    5. public class HotkeyChangeScene : MonoBehaviour
    6. {
    7.    
    8.     [MenuItem("Tools/SceneSwap %g")]
    9.     static void SceneSwap()
    10.     {
    11.         EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
    12.         var scene = EditorSceneManager.GetActiveScene();
    13.         if (scene.name == "!!Fish_Factory") EditorSceneManager.OpenScene("Assets/Default.unity");
    14.         else EditorSceneManager.OpenScene("Assets/!!Fish_Factory.unity");
    15.  
    16.     }
    17.  
    18. }
    This is the offending code, it's greatly helps me swap scenes quickly, but whenever i want to do a build i have to nuke the above code to get it to compile. Is there a way to have this code ignored for actual game builds since it's obviously only needed for in engine work?

    Thanks in advance.
     
  2. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    539
    Yeah, just put it inside an Editor folder.
    For example, create a folder called Editor in the assets directory and put the script inside it.
    For more information check out this tutorial: An Introduction to Editor Scripting

    Hope this helps!
    Thanks.
     
    Jeff-Berry likes this.
  3. Jeff-Berry

    Jeff-Berry

    Joined:
    Aug 31, 2012
    Posts:
    99
    Absolutely did the trick, looked everywhere for this answer before posting this.
     
  4. ibbybn

    ibbybn

    Joined:
    Jan 6, 2017
    Posts:
    66
    You can also just use
    #if UNITY_EDITOR
    ...
    #endif
    to exclude parts of scripts from builds.