[SOLVED] Custom Property Drawer without folding

Hello,

I have a custom property drawer to print an integer vector as read-only value.

The code is like this:

[CustomPropertyDrawer(typeof(IntVector4))]
public class IntVector4Drawer : PropertyDrawer
  {
    public override void OnGUI(Rect Position, SerializedProperty Property, GUIContent Label)
    {
      IntVector4 Vector = new IntVector4(
        Property.FindPropertyRelative("mX").intValue,
        Property.FindPropertyRelative("mY").intValue,
        Property.FindPropertyRelative("mZ").intValue,
        Property.FindPropertyRelative("mW").intValue
        );
     
      EditorGUI.BeginProperty(Position, Label, Property);
      Position = EditorGUI.PrefixLabel(Position, Label);
      EditorGUI.PropertyField(Position, Property, new GUIContent(Vector.ToString()));
      EditorGUI.EndProperty();
    
    }
  }

Basically everything works: The values are visible in the inspector as read-only values. However the values have this little folding arrow at the side and I can fold and unfold them, even if there is no content to unfold. Is there any possibility to get rid of this folding symbol?

This is an image:
3189167--243456--Folding.png

If you want it read only then ditch all the property stuff and instead use:

EditorGuiLayout.LabelField (or probably EditorGUI.LabelField in your case)

1 Like

Thank you, it solves perfectly my issue here.

The final code is:

public override void OnGUI(Rect Position, SerializedProperty Property, GUIContent Label)
{
  IntVector4 Vector = new IntVector4(
    Property.FindPropertyRelative("mX").intValue,
    Property.FindPropertyRelative("mY").intValue,
    Property.FindPropertyRelative("mZ").intValue,
    Property.FindPropertyRelative("mW").intValue
    );
  
  Position = EditorGUI.PrefixLabel(Position, Label);
  EditorGUI.LabelField(Position, Vector.ToString());     
}

And this is how it looks now:
3196500--244192--hex.png

1 Like

No worries!