- Home /
Build error: The type or namespace name 'UnityEditor' could not be found.
Hi.
It was my first attempt to build my game after updating to Unity 4.3, and this is what I got in the console after clicking 'Build':
The error is referencing to the highlighted line of the script on the right. I am unsure what to do, as the line is clearly correct, and it compiles fine, until I try to build the game.
It is an editor script, and it is only there to allow me to quickly clear all PlayerPrefs data. I do not need the script during runtime. Is there a way to exclude it from the build? If so, could that make the error disappear? Or could I deal with this error some other way?
Thanks in advance!
Answer by steakpinball · Nov 16, 2013 at 07:04 AM
The UnityEditor
namespace is not available in builds.
The easy solution is to put the script in a folder named Editor
. Anything inside of folders named Editor
is not included in builds. Since the entire script can be excluded you should do this.
Side note: When you want to exclude only part of a script you can enclose it in compiler flags.
// Runtime code here
#if UNITY_EDITOR
// Editor specific code here
#endif
// Runtime code here
Side note 2: Your ClearPlayerPrefs
class should inherit from ScriptableObject
since it shouldn't be attached to objects.
Be very, very careful inheriting from ScriptableObject. Due a limitation in how Unity uses that and it's prefab system, you can run into a lot of problems trying to create prefabs from objects that use ScriptableObject classes. If you have a $$anonymous$$onoBehaviour that adds a list with a nice editor and the objects in the list are ScriptableObjects, and then you try to make a prefab of a GameObject with that list on it, and duplicate the prefab? Very bad things happen. See more here and VOTE IT UP: http://feedback.unity3d.com/suggestions/serialization-of-polymorphic-dat
Unless you are totally sure your class will be independent and none of its pieces used by other $$anonymous$$onoBehaviour classes, I would just use $$anonymous$$onoBehaviours and go through the trouble of managing that.
@brianturner But what if I need the UnityEditor namespace in every Build?
SerializedObject so = new SerializedObject(specialCircleParticleSystem);
so.FindProperty("Shape$$anonymous$$odule.radius").floatValue = specialOuterCircleRadius;
so.Apply$$anonymous$$odifiedProperties();
I'm using it to change the radius of a Particle System dynamically.
Felix
@felixpk Sorry to say you will need to find another way to do it. The UnityEditor
namespace can not be used in builds. Can't be done. It literally means the unity editor. You should ask a new question to find alternatives.
,And how to apply properties to serialized object in build? I work with inputmanager. And I need to work with it in build?
See my response above to felix. SerializedObject
can't be used in builds. I recommend finding a new approach.
I have encountered the same error but can't fix it with above-mentioned solution. I'm using TransformUtils utility from UnityEditor library and can't find any workaround for android platform.