- Home /
'CustomEditor' is not a attribute class
Hi there, I am on unity version 2017.1.0.f3 and for some reason an error that was not happening before, now occurs, and I didn't even change the editor script nor the Graphic script, anyone knows what might be causing, the - 'CustomEditor' is not a attribute class - to trigger?
that occurs in the line where is says
[CustomEditor(typeof(Graphic))]
this is the beginning of that script:
#if UNITY_EDITOR
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(Graphic))]
public class GraphicEditor : Editor {
Any help would be appreciated :)
Your editor script should be in a folder called Editor (and so won't need the "#if UNITY_EDITOR" -- though it also won't hurt anything).
DId you move the script to another folder or rename the Editor folder?
Answer by Bunny83 · Sep 20, 2017 at 11:47 PM
You most likely created a class with the name "CustomEditor" which hides the class "UnityEditor.CustomEditor".
The best and recommended solution is to rename your own class to something else. However if you want to keep that class you have to use the fully qualified name:
[UnityEditor.CustomEditor( typeof(Graphic) )]
Thanks alot man! I had added alot of assets, from the assetstore and that created that class
<3
As i thought -.-
And that's why you should use namespaces, especially when you create assets for the assetstore. The only point of namespaces is to avoid name collisions. As long as the file where you need the CustomEditor attribute doesn't need anything from that custom namespace the problem would be already solved.
namespace $$anonymous$$y.Awesome.Subnamespace
{
public class CustomEditor
{
}
}
namespace Another.Completely.Different.Namespace
{
public class CustomEditor
{
}
}
This would be perfectly fine. Your project would now have 3 completely different classes with the name "CustomEditor" which have nothing to do with each other. If something is in a namespace you need to explicitly use a "using" statement to bring the classes in that namespace into the file scope. However if a class is declared in the global namespace you can't make it "disappear" since the global namespace is, well, globally available.
To be actually 100% sure to use the right class you would use:
global::UnityEditor.CustomEditor
In case some crazy person created a class with the name "UnityEditor" or created a sub namespace called "UnityEditor" in which case this is the only way to actually reach the correct namespace. For more information see the microsoft docs