Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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:
    520
    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:
    42
    You can also just use
    #if UNITY_EDITOR
    ...
    #endif
    to exclude parts of scripts from builds.