Error building Player because scripts had compiler errors

Hi everyone

I have a problem building my game and I have no idea why.
When it starts compiling scripts, the progress bar doesn’t begin and I receive this error message:

“The type or namespace name “UnityEditor” could not be found. Are you missing a using directive or an assembly reference?”

When I clic on it, it creates a scripts in the Assets folder, pointing to the line 2:

I tried to delete scripts, prefabs, etc, but it still sends me this message.
I use CameraPath and iTween add-ons, would it be possible that it cames from them?

Thanks for all the help I can get!

You’re going to need to fix the error. So, you’re using UnityEditor, which means your script is an editor extension. That code is not available at run-time. (So, for example, EditorWindow is all about creating new window in, um, the editor, and you cannot do this at runtime.) If you refer to the documentation:

you’ll read:

“Note: This is an editor class. To use it you have to place your script in Assets/Editor inside your project folder.”

So this reminds you that your script needs to be moved into a folder called Editor. (The build system knows that scripts inside the Editor folder are to do with extending the editor, so doesn’t bother to try and compile them into the built application.)

I was having the same problem however easily found a fix.

Go into every Script you have in that unity project and double check the first lines, the ones which say “Using UnityEngine” and “Unity System Collections”. I had only added to these lines with a “Using UnityEngine.UI” however when I was going through ALL my scripts for that project I found that there a few extra ones there that weren’t there when I started and I had not added (they added themselves there) , for example there was a “Using System Collections XMP” or something random like that. Simply delete these, save the script and you should be good to go.

I have no idea why they are there and what type of problem they seemed to cause however I can now build my project to android problem free now.

In my case, although game ran in play mode, it would not build to a physical Android device, with same error message as you. The problem turned out to be a playmode test file. I deleted the file, and the problem was fixed.

I was using one Editor Extention to clear player pref.
I put that script in Editor folder as suggested by @Graham-Dunnett and it solved.
Thanks :slight_smile:

I get this error and have tried everything and still cant sort it after reading everything here

Sometimes the “hidden” compilation error is stuck between Warnings that appear in console after building, and can be found by scrolling little higher in Console Window after failed build. Easy to miss in those circumstances.