- Home /
PropertyField for a list marked with [HideInInspector]
I want to hide a list in the inspector and show it only under specific conditions.
[SerializeField, HideInInspector]
private List<int> _myList = null;
In my custom editor, I then try to show the property field.
SerializedProperty serializedProperty = serializedObject.FindProperty("_myList");
EditorGUILayout.PropertyField(serializedProperty, true);
However, even though I set includeChildren
to true, it shows the name of the property, but nothing else (size or children).
Is there a way to make this work ?
Answer by Adam-Mechtley · Apr 28, 2017 at 10:42 AM
If you have a custom editor where you are controlling the conditions under which it is displayed, why do you need the HideInInspector
attribute on it?
Because I want to have it hidden by default. If the condition is met, I'll show it in OnInspectorGUI. But drawing all the propertyfields of my object by hand is tedious, I'd rather only override the behaviour only for specific properties.
Edit : Just to be clear, my problem is not "How can I show or hide a list under specific conditions", I have other ways of doing that if need be. I just need to know if there is a way around this specific HideInInspector issue. If there's not, I'll implement this another way.
Understood; so it sounds like you draw the default inspector and then only implement special conditions for ones that are marked as hidden by default.
The problem is that the default drawer used by EditorGUI.PropertyField()
iterates through children using SerializedProperty.NextVisible()
rather than SerializedProperty.Next()
, which in this case will pick up nothing since the parent property is not visible.
Right, that makes sense. I guess I just have to iterate on the child properties myself and draw a property field for each child then. Thanks for the explanation !
Your answer
Follow this Question
Related Questions
Saving editor-only variables 0 Answers
Serialization with custom editor, prefab not saving (again) 1 Answer
Displaying System.objects not serialized by Unity in a Custom Editor 0 Answers
How to create a new SerializedProperty? 0 Answers
Invalid iteration - (You need to stop calling Next when it returns false) 2 Answers