- Home /
OnInspectorGUI Never called
The following code doesn't work, "What" is never logged out.
[CustomEditor(typeof(Stat))]
public class StatDrawer : Editor
{
public override void OnInspectorGUI()
{
Debug.Log("What");
}
}
I'm actually using the OdinEditor class instead, but neither class functions correctly.
Things I've tried
Checked the OdinInspector preferences to make sure Stat is being drawn by StatDrawer
Ensure Stat exists
Checked my log level to ensure Editor logs are being printed
Edit:
The file is also under an Editor/ directory.
I've been stuck on this for several days now, can anyone explain?
Answer by Vega4Life · Dec 10, 2018 at 02:45 AM
More than likely, you don't have StatDrawer class in an Editor folder. The folder can be anywhere, you can have multiple of them, it just needs to be named 'Editor' and your editor scripts go in them - or they don't work.
Nope thats not it unfortunately, its in an Editor folder.
Then some shenanigans is going on that isn't this code. If I copy your CustomEditor script, create a blank Stat class, put the CustomEditor in an Editor folder, it works for me. :(
Answer by heinrichs81 · Apr 29 at 10:15 PM
Hello there,
I had the same problem, and solved it the following way:
Starting Point I tried to make a Custom Editor for a Class, that NOT inherits from MonoBehaviour. I used that base class inside a MonoBehaviour Script. That Script was attached to a GameObject. The Class shown up in the Inspector of that GameObject, but OnInspectorGUI() never called.
My Solution I used a PropertyDrawer instead using Custom Editor. PropertyDrawer could be more difficult to handle at first, but with a little bit of effort it is possible to create a clean and nice solution.
My Explanation I think Unity's "Editor" Class is not made for nested Classes. It can be used for Classes that not be assigned in other Classes.