- Home /
namespace name `UnityEditor' could not be found
hi , I hope find solution to my problem here.
I have this code for build menu of assetBundle options
using UnityEngine;
using UnityEditor;
public class ExportAssetBundles : MonoBehaviour {
[MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]
static void ExportResource () {
// Bring up save panel
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0) {
// Build the resource file from the active selection.
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
Selection.objects = selection;
}
}
[MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")]
static void ExportResourceNoTrack () {
// Bring up save panel
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0) {
// Build the resource file from the active selection.
BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path);
}
}
}
the problem happen while build app game it show me this error
Assets/Scripts/menuAssets.cs(7,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing a using directive or an assembly reference?
and this also
Error building Player because scripts had compiler errors
Answer by paulaceccon · Feb 09, 2013 at 05:53 PM
If you came here looking for the error:
"The type or namespace name 'Animations' does not exist in the namespace 'UnityEditor'"
This is because you are maybe trying to access the AnimatorController component inside your script that is inside UnityEditor.Animations and, as said in the link posted by paulaceccon, the UnityEditor (and all it's sub namespaces) are not compatible/loaded on builds.
To solve this specific issue, replace it with RuntimeAnimatorController.
Answer by Chonguy-Wang · Aug 14, 2016 at 03:42 PM
when i move the script file into the editor folder, it fixed.
Answer by FlightOfOne · Nov 06, 2018 at 04:30 PM
I got this error when I tried to build with custom attributes and property drawers, which uses UnityEditor.
Using preprocessor fixed it for me, probably the same reason as when moved to editor folder. Is one better than other?
#if UNITY_EDITOR
//--code--
#endif
Answer by BAbbas · Feb 26, 2017 at 06:28 PM
Delete unwanted resources and especially scripts those are not associated with any GameObject component or not linked with other classes in object form or move ur scripts into "editor" folder, it really solved my problem
Answer by Mordizer · Nov 11, 2020 at 09:24 PM
I had this issue inside a third party asset and I got around it by adding a reference to the UnityEditor.dll in the project file.