Custom Inspector, NotSupportedException
Hi,
I just tried to write a custom inspector script for a project and tried to use reflection to get the properties of my class and now I always get this Error: NotSupportedException: Property rigidbody has been deprecated. And my Inspector doesn't show the properties.
Here's my code:
using UnityEngine; using UnityEditor; using System.Reflection;
[CustomEditor(typeof(Navigation))] public class NavigationInspector : Editor {
public override void OnInspectorGUI()
{
//base.OnInspectorGUI();
Navigation nav = (Navigation)target;
PropertyInfo[] properties = nav.GetType().GetProperties();
foreach(PropertyInfo property in properties)
{
if(property.GetValue(nav, null).GetType() == typeof(int))
{
property.SetValue(nav, EditorGUILayout.IntField((int)property.GetValue(nav, null)), null);
}
}
}
}
Do you find any errors here ?
Edit:
Navigation Class:
using UnityEngine; using System.Collections.Generic;
public class Navigation : MonoBehaviour {
public int intProperty = 10;
[Header("Nav Mesh Visualization")]
public bool drawMeshInEditor = true;
public bool onlyWhenSelected = true;
private List<NavObstacle> obstacles;
// Use this for initialization
void Start () {
// Get all obstacles in the Scene
foreach(GameObject obstacle in GameObject.FindGameObjectsWithTag("Obstacle"))
{
obstacles.Add(obstacle.GetComponent<NavObstacle>());
}
}
void Update()
{
}
void OnDrawGizmos()
{
// Check if Mesh should be drawn
if (!drawMeshInEditor || onlyWhenSelected)
return;
DrawNavMesh();
}
void OnDrawGizmosSelected()
{
// Check if Mesh should be drawn
if (!drawMeshInEditor || !onlyWhenSelected)
return;
DrawNavMesh();
}
private void DrawNavMesh()
{
Gizmos.color = Color.cyan;
Gizmos.DrawWireCube(Vector3.zero, new Vector3(2, 2, 2));
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612081913im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I modify 'SerializedProperty' that contain 'Array' in Custom inspector? 0 Answers
Objects in Custom Editor Resetting on Play 1 Answer
Custom Inspector for a list of custom class members. 2 Answers
Custom inspector. Pick one bool from a list. 1 Answer
Hot Reload - Call back problems 0 Answers