- Home /
How to prevent drawing DecoratorDrawer (like Header or Space) during EditorGUI.PropertyField?
Hello!
I want to draw property with EditoryGUI.PropertyField but without drawing any Decorators (like Header and Space)
I've wrote example to show what I mean:
[CreateAssetMenu]
public class Parent : ScriptableObject {
public Child child;
}
[Serializable]
public class Child {
[Header("Header")]
public string field;
}
[CustomPropertyDrawer(typeof(Child))]
public class TestDrawerPropertyDrawer : PropertyDrawer {
public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) {
EditorGUI.BeginProperty(rect, label, property);
EditorGUI.PropertyField(rect, property, label, true);
EditorGUI.EndProperty();
}
}
And I get the following result:
I tryed to use (or not) EditorGUI.BeginProperty
& EditorGUI.EndProperty
; I even try EditorGUI.MultiplePropertyField
but it draws headers too (and it looks weird).
Does anybody know how to ommit decorators?
I think the solutions are found here:
http://catlikecoding.com/unity/tutorials/editor/custom-list/
Nice tutorial but there is nothing about property decorators =(
Answer by steo · Aug 28, 2017 at 01:56 PM
I found a workaround using reflection (I know, it is not a true way but I need some solution).
typeof(EditorGUI)
.GetMethod("DefaultPropertyField", BindingFlags.NonPublic | BindingFlags.Static)
.Invoke(null, new object[]{rect, property, GUIContent.none});
Your answer
Follow this Question
Related Questions
GetPropertyHeight infinite recursion on drawer 1 Answer
PropertyDrawer always errors when calling OnInspectorGUI 1 Answer
Why is my propertydrawer being automatically disabled? 1 Answer
Property Drawer Similar To AABB or Bounds? 0 Answers
Should EditorGUILayout.PropertyField work with serializable classes? 1 Answer