- Home /
"using UnityEditor;" throws an error?
This is so strange. I've imported an asset from the asset store (Volumetric Lines by Johannes Unterguggenberger), and when I try to build a standalone player Unity throws this error at me:
"The type or namespace name `UnityEditor' could not be found. Are you missing a using directive or an assembly reference?"
I have no idea what could be causing that. I've tried resyncing MonoDevelop, restarting Unity, etc. Nothing seems to work. It causes my whole script to break, too, because I use things from the "UnityEditor library." I'm running Unity 5.1.2. Does anyone have any idea what could be causing this? Here's a pastebin link of the entire script that causes errors: http://pastebin.com/x9q1ESPu
Answer by legion_44 · Aug 08, 2015 at 02:21 PM
Every script that uses UnityEditor namespace must be in folder called "Editor" because that namespace can only be used in editor. Also You can place editor code outside of "Editor" folder if you enclose it in #if UNITY_EDITOR and #endif. For example:
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class PlayerAndEditorClass : MonoBehaviour
{
#if UNITY_EDITOR
// editor code
#endif
// rest of the code
}
You cannot use classes from UnityEditor namespace outside of unity editor.
That did the trick! Thanks for such a simple and clear answer.
Your answer
Follow this Question
Related Questions
Calling C# Namespace from Boo 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Trouble using savepanel and unityeditor namespace in built exe 0 Answers
Microsoft Visual C# Compiler error 0 Answers