- Home /
OnInspectorGUI not working
I am trying to draw a button to a custom editor so i can call a function by clicking a button.
currently my script looks like this:: using UnityEngine; using UnityEditor;
[CustomEditor(typeof(TerrainManager))]
public class BuildButton : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
TerrainManager builder = (TerrainManager)FindObjectOfType(typeof(TerrainManager));
if (GUILayout.Button("Generate Grid"))
{
builder.GenerateTerrain();
}
if (GUILayout.Button("Clear Grid"))
{
builder.ClearTerrain();
}
}
}
But it returns the error: OnInspectorGUI()' is marked as an override but no suitable method found to override
. I have the script in an "Editor" folder as that is required for Editor scripts.
I know i'm supposed to do it like this as i've used it before in other projects, and pasting this code in a clean project also does what i want.
Anyone has any ideas why it may not work currently?
I'm using unity version 2018.3.0f3 on windows
Answer by Tomer-Barkan · Nov 16, 2018 at 06:29 PM
I happen to be using the exact same version and copy-pasted your code as is, only changed TerrainManager to Button, and it works perfectly.
Did you copy-paste your code? Did you change anything? The only thing I can think of is that you may have another class named Editor somewhere in the project, and it inherits that instead of the builting unity editor class.
It turned out to be that an asset i had downloaded (But wasn't even using) indeed had a class named "Editor" that was overwriting the built-in Unity editor class.
Thanks for the reply!
Logged in just to say thank you! Could have never figured it out.
Your answer
Follow this Question
Related Questions
Using a CustomEditor in the inspector and also seeing normal inspector fields 1 Answer
How do you force a custom inspector to redraw? 7 Answers
Is there a way to draw on the scene view from an asset being inspected by the Inspector? 0 Answers
Callback when custom PropertyAttribute changes 0 Answers
OnInspectorGUI Custom Drawing? 1 Answer