Unity 4.1 Javascript compile - 'UnityEditor' not found

After upgrading to 4.1 this morning, MonoDevelop is reporting the following error for all javascript files in my project: “Namespace ‘UnityEditor’ not found, maybe you forgot to add an assembly reference? (BCE0021) (Assembly-UnityScript)”. I don’t use javascript primarily, so the error is limited to about a dozen third party files, but they’re from multiple third parties, and they all worked fine pre-upgrade. There are no errors reported by the Unity console; these are only showing up in MonoDevelop.

UnityEditor is properly referenced in the project assemblies. Dropping and re-adding it doesn’t help. Adding an import reference to the javascript file doesn’t address the issue, either.

Does anyone know how to fix this?

NOTE: This may have come as part of 4.0.1, I upgraded from 4.0 to 4.1.

I heartily advocate not building your project in MonoDevelop - just let the Unity Editor build it for you by saving and bringing the editor to the foreground - it’s a faster work flow, although annoying to have to tab between the windows to see the next error. For ages there were things like default parameters that would build fine in Unity but not in MonoDevelop.

For reference you can open the Javascript .unityproj project files in a text editor and delete the references there, or modify them. (Backup first). You are looking for the < ItemGroup> section:

  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.XML" />
    <Reference Include="System.Core" />
    <Reference Include="UnityEngine">
      <HintPath>/Applications/Unity 4.1/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll</HintPath>
    </Reference>
    <Reference Include="UnityEditor">
      <HintPath>/Applications/Unity 4.1/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll</HintPath>
    </Reference>
  </ItemGroup>

Be aware that using MonoDevelop to build your project has the following limitations:

  • MonoDevelop is often out of sync with the Unity build process so there are several things that will not compile that are actually fine.
  • MonoDevelop build is not the build path for your final executable
  • You don’t need to build using MonoDevelop in order to debug your code using MonoDevelop. See this link.

For me it was solved by deleting from :

  • Assembly-UnityScript.unityproj
  • Assembly-UnityScript-firstpass.unityproj

the UnityEditor related ref tag:

<Reference Include="UnityEditor">
  ..
</Reference>

I wrote a small tool that does this for you automatically. This makes creating, deleting, moving scripts (almost anything that forces Unity to recompile and rewrite the unityproj files) possible again:

Bitbucket (UnityBCE0021)

I have had the same problem… I have read that you could try and add UnityEditor and import it to the start of every problem javascript… Sadly this did not work for me. Maybe you’d have better luck.

Try and add this.

import UnityEditor;

Good Luck.

There was a workaround for this, but I can’t delete the references:

"

If you have UnityScript files in your project and get the UnityEditor namespace
reference not found issue, go to the “Solution” panel (at the left of the
MonoDevelop IDE) and open the “Assembly-UnityScript → References” branch.
Delete all the references in there EXCEPT the one to the “UnityEngine.dll”.
Then press F8 again to build from MonoDevelop.
You should be good to go.
But clearly there’s still a bug somewhere causing this error.
I’m just glad I found an easy way around it.
BTW, everytime I reopen MonoDevelop I see those references added again.
So I have to delete them again. But when working on a project you rarely
close MonoDevelop.

"