- Home /
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!
Answer by Graham-Dunnett · May 20, 2013 at 10:49 AM
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:
http://docs.unity3d.com/Documentation/ScriptReference/EditorWindow.html
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 just realized that apparently we can't answer on our own question page since there's not the message that I wrote back then: even if I accepted your answer at the time, I also wanted to say thank you, you helped me a lot (especially since I was in a hurry and you answered really quickly) and I now keep that folder "trick" in $$anonymous$$d ;)
HOLY CRAP! I HAD THE SA$$anonymous$$E ERROR AND YOUR $$anonymous$$ETHOD FIXED IT THAN$$anonymous$$SYOU SO $$anonymous$$UCH DUDE!
Answer by Arran2020 · Jul 30, 2020 at 11:58 AM
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.
I had the same issue went through all my scripts and found some system collections that I had not put in there e.g. I found
using UnityEngine.Video using UnityEditor using SecurtiyPolicy
in scripts that were not using these resources. I removed them and voilà!. Fixed!
Answer by RowanG1 · Nov 15, 2017 at 03:20 AM
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.
Answer by mbhagat · Dec 18, 2017 at 08:22 AM
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 :)
Answer by help00686 · Nov 09, 2018 at 07:34 PM
I get this error and have tried everything and still cant sort it after reading everything here
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 X$$anonymous$$P" 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.
Your answer