- Home /
Edit existing editor inspector?
I want to write custom inspector for one of my scripts. All I want to change is input method for one of the strings to popup (so instead of writing whole string everytime I choose it from premade list of strings, like enums). But the thing is it's VERY long inspector with a lot of variables and rewriting everything just for this one input just doesn't click for me. I'm very happy with how default inspector shows all the fields, expect this one string I want to change. Is there a way to do it without rewriting whole inpector on your own?
Answer by Bonfire-Boy · Aug 08, 2019 at 09:38 AM
Yes this kind of thing is certainly possible.
We have our own version of DrawDefaultInspector, which has a parameter allowing us to pass in a list of names of properties that we don't want it to draw.
It works by iterating over the SerializedObject's SerializedPropertys, calling EditorGUILayout.PropertyField to draw each property unless the property's name is found in the "don't draw" list.
A custom inspector can use this to draw the bulk of the inspector, and then handle the excluded properties in its own way.
The custom inspector calls this function, then does its own thing to draw the properties that have been excluded.
Not that using the above "exclusion list" method, the modified drawing has to be done either before or after the default drawing.
We've now actually moved on to using an overrides list. We pass through a set of objects that define override drawers for our DrawDefaultInspector function to use. That way, there's no change to the order in which the properties appear in the inspector.
Would that work in nest-in fields inside other serialized objects? I have fields inside objects inside other objects for my dialogue system, it looks like so screenshot and I want to change input method of Name field to a list with predefined names of actors (who says the thing).
Also is there a documentation for the thing you mentioned with some examples? I can't find it anywhere on unity manual, the DrawDefaultInspector() doesn't seem to take any parameters either for me.
Your answer
Follow this Question
Related Questions
Moving the input fields in a custom inspector 2 Answers
Customize how class attributes are shown in the Inspector? 0 Answers
Make a custom inspector that shows a group of variables in form of list 2 Answers
How to Hide/Show List or Array in the inspector based on a variable? 0 Answers
Prefix label greyed out when following component disabled 1 Answer