- Home /
"UnityEditor" could not be found
Hi. I'm really new to Unity and I'm currently creating a game where I need to do some painting dots, lines etc. I used "Handles" to do those paintings. Another thing I need are message boxes which are provided by UnityEditor namespace as EditorUtility.DisplayDialog .
So far I ran my game only in Editor and everything worked, but I wanted to build it and I got error "The type or namespace name `UnityEditor' could not be found. Are you missing a using directive or an assembly reference?". I did some googling and found this subject http://answers.unity3d.com/questions/316805/unityeditor-namespace-not-found.html but I'm not sure that I understand what people are saying there. Some people say that functionalities provided by UnityEditor can be used in Editor only, some people say that script using those should be moved to "Editor" folder. I hope that I can use those functionalities in a build (for Windows), because providing functionalities which work in UnityEditor only seems really weird to me... So I tried moving script GameManager.cs to Editor folder and when I did it I received following warning "The class named 'GameManager' is not derived from MonoBehaviour or ScriptableObject!" and indeed, the whole game is not working, although I got line "public class GameManager : MonoBehaviour {". Maybe I should create a new file and put there only a part of GameManager.cs ?
Is there a way I can use Handles and EditorUtility.DisplayDialog in Windows Build? What should I do?
EditorUtility.DisplayDialog
is an editor thing only. It's not a runtime GUI thing. You should make one yourself. When you put something in the Editor folder you're saying: This won't be included in the build, this is just when working inside the Editor.
Answer by tanoshimi · Jun 10, 2014 at 12:04 PM
The people that said you can't use functionality of the UnityEditor namespace in a build are correct. If you want that functionality in a game you'll have to write it yourself or find an asset that does it.
Answer by Nerevar · Jun 10, 2014 at 12:13 PM
Hello,
You can not build a MonoBehaviour class using the UnityEditor namespace elements. You have to create a specific script derived from editor class and put it in the editor folder. Then use on this script the functionnalities you want that needs the UnityEditor namespace.
A little example:
Your general Class:
using UnityEngine;
using System.Collections;
public class dialogue : MonoBehaviour {
public string message = "Hello World";
}
Your Editor script:
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(dialogue))]
public class dialogueEditor : Editor{
bool init;
public override void OnInspectorGUI(){
dialogue myScript = (dialogue)target;
if(!init){
EditorUtility.DisplayDialog("exemple", myScript.message,"Yes","No");
init = true;
}
}
}
Thank for your response, it definitely gives me some hope :)! But I can't make it working properly yet. After painting in function OnInspectorGUI() I got something like this picture in attachment which is probably not what I want :D. New message box pops out every time I'm switching focus on a list of objects on the left to "_G$$anonymous$$" (which is an empty object with script Game$$anonymous$$anager.cs assigned) and these lines and dots are painted ... on an inspector in fact :D. Of course I want these lines to be painted on a scene when I run my game.
[1]: /storage/temp/27540-unityzonk.png
@Nerevar: I think you should read the question more carefully. It's clear that Swistakk wants to use that things at runtime and not just in the editor.
@Swistakk: No, unfortunately there's no hopw ;) The UnityEditor namespace and it's related assembly just wraps functionality that belongs to the editor application itself. This assembly can't be used in a build. That's why it's called UnityEditor ;)
If you want to draw lines / dots at runtime, use the GL class.
For message / dialog boxes you might be able to use the ones that comes with .NET. It depends on what kind of dialog you need. Usually you would create such things with ingame graphics / GUI.
Here's an old example i did in the past to explain how FixedUpdate works ;) The whole thing is done with 1 script and uses the GL class to draw most things. The "windows" are normal GUI windows.
@Bunny83 Yes but to me it was not quite clear what he wanted to achieve as he looked not familiar with the editor.
And Yes if He wants special customed GUI elements at runtime he may have to code it himself.
Your answer
![](https://koobas.hobune.stream/wayback/20220613151223im_/https://answers.unity.com/themes/thub/images/avi.jpg)