- Home /
Nesting custom inspectors
I have two MonoBehaviours, let's call them A and B
public class A : MonoBehaviour
{
public B b;
...
}
public class B : MonoBehaviour
{
...
}
and a custom inspector for each:
[CanEditMultipleObjects]
[CustomEditor(typeof(A))]
public class AEditor : Editor
{
private SerializedProperty bProp
...
public void OnEnable()
{
bProp = serializedObject.FindProperty("b");
...
}
public override void OnInspectorGUI()
{
EditorGUILayout.PropertyField(b);
...
}
}
[CanEditMultipleObjects]
[CustomEditor(typeof(B))]
public class BEditor : Editor
{
...
}
Both objects require their own custom inspectors, and both need to be multi-editable (therefore requiring the use of SerializedProperties). In addition to being nested inside of A, B can also exist on its own, and needs to be editable in both cases.
When I select an object of type B, its custom inspector shows up nicely. Unfortunately, when I select an object of type A, instead of the custom inspector for B being nicely nested inside the inspector for A, I simply get a box with a link to the instance of B contained in A.
How can I get B's custom inspector to show up nested inside of A's inspector without duplicating code?
Your answer
Follow this Question
Related Questions
Invalid iteration - (You need to stop calling Next when it returns false) 2 Answers
Editor Targets are updated but SerializedPropertys arent 1 Answer
Can you have custom EditorGUILayout fields? 0 Answers
How to combine two buttons in one. Editor window 2 Answers
Custom Editor - Is there any way to detect whether the user is in Prefab editing mode? 1 Answer