Search Unity

Building error: namespace name `UnityEditor' could not be found

Discussion in 'Editor & General Support' started by angel_m, Dec 19, 2017.

  1. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Hi, when trying to build my project to Android, Unity give me this error and it stops the building process:

    Assets/Plugins/Editor/OneScript.cs(2,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing a using directive or an assembly reference?

    The offending script is inside the Editor folder, so I don't understand the error.

    Any idea?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    What version of Unity are you using? It should be possible to use Editor folders inside Plugins in 5.3 and above.
     
  3. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Ok, thanks, I 'm using Unity 5.1.4.
     
    karl_jones likes this.
  4. Vizepi

    Vizepi

    Joined:
    Jul 17, 2017
    Posts:
    2
    Hello,

    I have the same issue here with version 2017.3.0f3. I have 20 errors in an Editor script, all like this:

    Assets/Scripts/Engine/Security/Editor/BlackPropertyDrawer.cs(26,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing an assembly reference?

    I added some asmref files here :
    Assets/Script/Engine, Assets/Script/Game, Assets/Scripts/Edition with Edition depending on Game and Game depending on Engine.

    Any idea ?
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    asmrefs are the new way to define editor only code, the Editor special folder is the old way. They dont intermix.
    Any child directories will be included by the asmref. The Editor special folder will be ignored if it is included in the asmref. You should either move the Editor folder so it is not inside of an asmref or add another asmref inside of the Editor folder and set it to be Editor only.
     
  6. Vizepi

    Vizepi

    Joined:
    Jul 17, 2017
    Posts:
    2
    Thank you it works fine now!

    I added EngineSecurityEditor.asmref in the folder Assets/Scripts/Engine/Security/Editor and set it to Editor only.

    However, is it a way to add scripts from different folders to the same assembly ? Like my scripts from all my Editor folders ?
     
  7. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    No you would need to add each asmref as a reference. If you want that you should use the Editor special folder method and just make sure its not in a subdirectory of a asmref.
    Maybe change the structure you have so there's a master directory for editor and one for player code?
    Assets/Scripts/Engine/Player/
    Assets/Scripts/Engine/Editor/
     
    novicecode likes this.
  8. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,783
    Just got a query from a customer about compilation and Editor directories. Reserving judgement until I have done some more investigation, but on surface this change breaks every asset out there that has a custom editor... which if true, is absolute madness.
     
  9. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    It will only break them if you put them all under a single asmref. You should place additional asmrefs and make them editor only for any editor scripts.

    The new system is moving away from special folders and letting you decide how folders are compiled. So if you want the old way of having them in Editor folders use the old system, if you want the new way then use asmrefs but you will need to assign editor only asmrefs. We don't recommend mixing methods as the benefit is reduced.
    Nested asmrefs are fine. https://docs.unity3d.com/2017.3/Documentation/Manual/ScriptCompilationAssemblyDefinitionFiles.html

    It should also be possible to write your own editor script to auto setup asmrefs so that if you really wanted you could go through and find all the editor folders and add an editor only assmref although I would recommend you spend a little extra time and set it up manually so you can get the best configuration. Making sure that you have the minimum references for each.
     
    Last edited: Dec 25, 2017
  10. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,783
    Thanks for your response :) The interesting thing is that I have not added any asmrefs as my product (CTS) was published for an earlier version of unity.

    My customer just included my asset in their project, and it broke their build, and as I always test release builds of my products to make sure they are OK this came as a big surprise to me. My first thought was that she must have broken Unity somehow.

    I will issue a patch that controls how it should compile, but if the default behavior is now to include Editor folders then my sense is that there will be a massive community backlash as peoples projects start breaking.

    Btw. I think its a cool idea, but the default behaviour ought to be to honor the old way of building unless otherwise specified.
     
  11. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    It sounds like the user is placing your asset into a sub directory of an asmref which will break it if it has editor only scripts. You can solve this by providing your own asmref files with the asset so if they do make it a sub directory it will still work by using the asmrefs you provided. Using the default behaviour is actually not that simple. We need to know what assemblies need what references, if we just create a new assembly for every editor dir and reference everything then we end up back to before and gain no benefit to using asmrefs. Supporting the old method would make asmrefs somewhat pointless and confuse people when they find they gain no benefit from it or even find it increases compilation times.

    The default behaviour is to honour the old system, by using asmrefs your not default anymore ;)
     
    AdamGoodrich likes this.
  12. Xrystal

    Xrystal

    Joined:
    Mar 25, 2014
    Posts:
    203
    Thanks Karl. However, in my case I think the fact that Editor folders were being used for editor scripts inside the modules using them having asmref files in the root folder for that module was causing the problem. Removing the asmref files allows the project to compile fine or adjusting the Editor code to only run if in Editor Mode stopped them appearing as causes for the failure.

    Example folder structure I was using.

    No sub folders for third party assets
    Module1 - Third Party Asset
    |__m1.asmref
    |__Editor
    .....|__m1.cs
    Module2 - Third Party Asset
    |__m2.asmref
    |__Editor
    .....|__m2.cs
    Module3 - Project Module
    |__m3.asmref
    |__Editor
    .....|__m3.cs
    etc

    It might be that my understanding of the use of the asmref's but my understanding was that using them would allow the project to load faster and compile times cut down as once a particular set of files were compiled they did't need to unless their referenced files were changed. Loading time did indeed seem faster but first test compile failed complaining of the Editor scripts in a sub folder of a folder containing an asmref.
     
  13. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
  14. alan0319

    alan0319

    Joined:
    Oct 17, 2023
    Posts:
    2
    Assembly defition file setting platform/deselect all and check Editor only,it's sloved~