Build error: The type or namespace name 'UnityEditor' could not be found. (86955)

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’:

[17981-screen+shot+2013-11-16+at+05.54.58+am+(2).png|17981]

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!

2 Answers

2

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.

@brianturner But what if I need the UnityEditor namespace in every Build? SerializedObject so = new SerializedObject(specialCircleParticleSystem); so.FindProperty("ShapeModule.radius").floatValue = specialOuterCircleRadius; so.ApplyModifiedProperties(); 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][1] to find alternatives. [1]: http://answers.unity3d.com/questions/ask.html

,And how to apply properties to serialized object in build? I work with inputmanager. And I need to work with it in build?

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.

,And how to apply properties to serialized object in build?
I work with inputmanager. And I need to work with it in build?