- Home /
Base MonoBehaviour Editor, foldout with base properties, child properties untouched.
Hello, I would like to try and create a base class that all my MonoBehaviours can inherit from, where I can control stuff like logging options etc. How ever, I dont want to clutter up my serialized variables in my editor most of the time. So I want to add a foldout using a CustomEditor. I have set it up to override the OnInspectorGUI() method. But what I struggle to figure out is, how do I do the following?
BaseBehaviour : MonoBehaviour
[SerializedField] bool showLogs;
TestBehaviour : BaseBehaviour
[SerializedField] bool testBool;
And then have the editor script for the BaseBehaviour draw out...
if (foldout) {
DrawAllFieldsInBaseBehaviour (aka showLogs, in this case)
}
DrawAllFieldsInInheritedBehaviour (like default, but EXCLUDING. showLogs)
To clearify, I need help to write these two Draw methods above. If at all possible, I don't know a lot about how serialization works, so I might not even be able to say DrawAllFieldsInInheritedBehaviour
Answer by Ledii · Feb 10, 2019 at 10:12 PM
After some more searches, I did stumble upon some useful functions. So I now have access to all the serialized fields. Using:
SerializedProperty property = serializedObject.GetIterator();
while (property.NextVisible(true))
{
properties.Add(property.name);
Debug.Log("Prop: " + property.name);
}
I get both showLogs AND testBool. And I can draw the remaining properties using:
DrawPropertiesExcluding(serializedObject, excludedProperties.ToArray());
So now I actually only need a way to determine that only showLogs belongs in the BaseBehaviour class!
I did eventually figure out something that worked like I wanted. It was a headache to try and look through what all of the results was from several functions. In case someone finds this concept useful, I you can find my final code here: https://pastebin.com/uzkzRzAs
Your answer
![](https://koobas.hobune.stream/wayback/20220612191511im_/https://answers.unity.com/themes/thub/images/avi.jpg)