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. Dismiss Notice

Can't build due to CS0246: The type or namespace name 'Editor' could not be found

Discussion in 'Windows' started by ruimtebever44, Feb 7, 2022.

  1. ruimtebever44

    ruimtebever44

    Joined:
    Jan 3, 2020
    Posts:
    6
    Hello. When I try to build my game I get 400 something errors and they all seem to have something to do with Unity trying to include Editor scripts.

    Assets\Plugins\AraTrail\Editor\AraTrailEditor.cs(9,37): error CS0246: The type or namespace name 'Editor' could not be found (are you missing a using directive or an assembly reference?) BUILD_ERRORS.png

    As you can see in the path in the error message above, the script is already placed in an Editor folder. As do all the other files mentioned in the errors. Which I'm pretty sure is the intended way to exclude them from your build.

    I'm using Unity 2021.2.10f1 Personal on Windows 10.

    Why is Unity trying to include the editor scripts into my build? Any idea what I should do to solve this issue?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,504
    Is there an .asmdef file somewhere in that folder that directs Unity to include it for the build?
     
  3. ruimtebever44

    ruimtebever44

    Joined:
    Jan 3, 2020
    Posts:
    6
    Hey, thanks for the response. It was indeed related assembly definitions, but I had no .asmdef file in the editor folders.

    Here's what worked for me in case someone else runs into this in the future:
    I had to make new assembly definitions or assembly definition references in every Editor folder I had. This includes any asset store plugins I was using (even the really popular ones). These Editor .asmdef's should only point to "Editor" and no other platforms.

    It looks like naming your folders "Editor" is only half the solution to not include the content in your build if you are using assembly definitions at all. Weird but ok. Maybe I'm wrong but it works now.
     
  4. hotlabs

    hotlabs

    Joined:
    Apr 11, 2021
    Posts:
    10
    I also found an alternative option to creating a /Assets/Editor folder, just using conditional compiling worked for me:
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. public class MyScriptEditor: Editor {
    3. ... your custom editor code here ...
    4. }
    5. #endif