- Home /
Custom Inspector "Multi-object editing not supported"
I have been playing with the custom inspector and I can't seem to get it to work correctly with inheritance. Here are my files, I will explain what I tried after the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ParentObject : MonoBehaviour {
public int i = 0;
public int j = 0;
}
Class 2:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChildObject : ParentObject {
}
Editor Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(ParentObject), true)]
public class ParentEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
ParentObject p = (ParentObject) target;
EditorGUILayout.LabelField("i", p.i.ToString());
}
}
I attached both classes to the main camera to see the inspector. In this set up both say "Multi-object editing not supported". When I remove the editorForChildClasses boolean the child class will show the expected (allows me to modify i and j) but ParentObject is still the same.
I want to have it so that I can have a few things in the Parent Editor then have another editor for the child class that has its own stuff along with the parent stuff.
Thanks for any advice!
Update 1: For some reason the Editor script started to work for ParentObject. I added a new editor script to the Editor folder to test it and it started working. It still doesn't work for ChildObject when editorForChildClasses is on but it's a step in the right direction.
I've seen that a common cause of this problem is the file isn't in the Editor folder, that isn't the cause of my problem, but maybe it will help someone else that has this happen.
Answer by WaldoAtUSC · Apr 10, 2018 at 05:13 PM
Okay, kind of an annoying work around but this works, hope it helps someone:
ParentObject and ChildObject are the same
Added a method to ParentEditor:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(ParentObject))]
public class ParentEditor : Editor
{
public override void OnInspectorGUI()
{
ParentObject p = (ParentObject) target;
EditorGUILayout.LabelField("i", p.i.ToString());
EditorGUILayout.LabelField("j", p.j.ToString());
}
static public void RunForChild(ChildObject c)
{
ParentObject p = c;
EditorGUILayout.LabelField("i", p.i.ToString());
EditorGUILayout.LabelField("j", p.j.ToString());
}
}
Made a ChildEditor class:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(ChildObject))]
public class ChildEditor : Editor
{
public override void OnInspectorGUI()
{
ParentEditor.RunForChild((ChildObject)target);
}
}
Kind of annoying that it didn't just work, but this is fine for me.
You can use:
[CustomEditor(typeof(ParentObject), true)]
The second property enables Editor For Child Classes
Answer by stephanholding · Mar 01, 2019 at 12:40 PM
You can use [CustomEditor(typeof(ParentObject)), CanEditMultipleObjects]
. This way you can edit multiple instances of your custom editor in the inspector, at the same time.
While this is true, just adding this attribute is not enough. The actual editor code has to handle multiple objects as well, which his code doesn't since he uses the "old" target object. $$anonymous$$ulti-object editing should be done with the SerializedObject / SerializedProperty classes. Every editor already has the serializedObject property.
If you can't or don't want to use the SerializedObject, you have to use the "targets" array and do any multi object relevant things yourself. The targets array will contain all objects. Though if you don't know what you're doing, it's easy to completely mess up everything.
Answer by Dailyalex · Nov 06, 2021 at 01:50 PM
My anwser is not exactly about inheritance, but I got same error message. That's why maybe my anwser will help to somebody.
I had simplier example and i was pretty sure, that code looks good, but I still got this warning message. What I did, I just removed component and added it back. And this warning dissapeared.
Doing this one in after doing what stephanholding did worked perfectly for me :D
Answer by zibolo · Apr 23 at 10:41 AM
For me I solved the problem by making sure that the name of the editor script/class was the same as the name of the class of which I wanted to modify the editor + "Editor". So if your class is called "MyObject", the editor class should be called "MyObjectEditor". And everything worked smoothly.
Your answer
Follow this Question
Related Questions
Should I use Inspector or custom editor window? 1 Answer
Inspector Overlapping Text Label at a Position 1 Answer
Custom editor UnityEvents in List 0 Answers
Custom inspector editor - how to put new editor fields in a specific place 1 Answer
Show texture (image box) in inspector with custom editor [C#]? 3 Answers