Can't get Custom Editor to display
I have followed several tutorial on setting up a custom editor for components in Unity but all result in nothing changing in Unity. Any ideas what I'm missing? Thanks!
File: Assets\Editor\PlanetControllerInspector.cs
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(PlanetController))]
public class PlanetControllerInspector : Editor {
public override void OnInspectorGUI()
{
GUILayout.Label("TEST");
}
}
File: Assets\Scripts\PlanetController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlanetController : MonoBehaviour {
public Camera Cam;
public int MaxPlanetResolution = 3;
public int QuadSize = 16;
public int PlanetSize = 32;
....
}
Answer by Backside2357 · Jan 20, 2018 at 08:52 PM
Your code works, what exactly are you doing?
Btw: Consider enclosing your whole class with the #if UNITY_EDITOR compiler tag (including the using UnityEditor !):
#if UNITY_EDITOR
using UnityEditor;
[CustomEditor(typeof(TestScript))]
public class TestScriptGUI : Editor {
...
}
#endif
Otherwise you will get a compiler error as soon as you try to build your project.
Added the compiler tags and the project builds still but the GUI never changes in the inspector :/
Well, it works for me and I do the following:
Create a new C# script called TestScript.cs
Create another new C# script called TestScriptGUI.cs
Edit the TestScriptGUI.cs and replace the code with this (which is basically exactly your code):
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(TestScript))]
public class TestScriptGUI : Editor {
public override void OnInspectorGUI()
{
GUILayout.Label("TEST");
}
}
Drag the TestScript.cs on the Cube GameObject Inspector
The Inspector now shows "TEST"
Your answer
Follow this Question
Related Questions
Custom Editor: Array of Structs with elements hidden by toggles 0 Answers
Add multiple custom editors for same type of object. 0 Answers
Objects in Custom Editor Resetting on Play 1 Answer
How to create a selection menu in the inspector for classes and their methods? 1 Answer
How to select a MonoBehaviour in inspector from a cusom editor? 0 Answers