Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity Editor class not found

Discussion in 'Scripting' started by angel_m, May 12, 2016.

  1. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    After importing some assets from the store, I get the warning "Unity Editor class not found" as a compiling error. The offending scripts are from those assets.
    Any idea?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    scripts are in the wrong place in the project? I believe all editor scripts need to be in folders called "Editor"
     
  3. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    I already checked that, but it wasn't the problem.
    Thanks.
     
  4. Kamilche_

    Kamilche_

    Joined:
    Jan 11, 2015
    Posts:
    75
    I just had this problem yesterday. In Unity, you can have a code file import the UnityEditor namespace; but when you go to build it, it will give you the 'UnityEditor class not found' error you reference above.

    It takes careful testing to catch stuff like this.

    My problem was, I needed to know the AssetDatabase path of a gameObject, at runtime. The code I created threw errors at runtime, that didn't exist at design. It was that same error 'UnityEditor not found' you reference above.

    I finally took the logic out of the class, and put it in a class, in the UnityEditor folder. I have responsibility for loading/saving objects split between two classes now, which is not good - but it's kind of forced on you when UnityEditor isn't available at runtime.
     
  5. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Thanks for the information.
     
  6. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    UnityEditor is not available in builds (which makes sens).
    If you are using this namespace, place your script into a Editor folder (folders named "Editor" are not included in builds). This will highlight the errors from the editor so you will know about the errors before building.
    Also, you could use:

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. // Code that makes use of UnityEditor
    3. #endif
    To exclude portions of code from your builds.