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

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?)

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?

Is there an .asmdef file somewhere in that folder that directs Unity to include it for the build?

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.

3 Likes

I also found an alternative option to creating a /Assets/Editor folder, just using conditional compiling worked for me:

#if UNITY_EDITOR
public class MyScriptEditor: Editor {
... your custom editor code here ...
}
#endif

I will present a specific solution to the large number of errors that occur when trying to build assets obtained from UnityAssetStore or other sources.

For example, this is an example of an asset called FinalIK, but add asmdef to the Editor directory.

The asmdef refers to the asmdef of the asset, and a valid plat form is set in the Editor.

This will prevent the error from being displayed.