EditorGUILayout.PropertyField without Foldout

When I use EditorGUILayout.PropertyField for an object inspector adds foldout triangle. How can I show PropertyField inspector without foldout?

EditorGUILayout.PropertyField(MyObject);

9025909--1245343--upload_2023-5-20_21-2-36.png

Is it impossible?

I have same question but for EditorGUI.PropertyField

And the same answer applies.

I know this is an old thread, but I found a way to do this that it doesn’t seem anyone else has mentioned. What you can do is make a custom property drawer for your serialized property that doesn’t include the foldout. This takes a bit of code, but it can be done in a way that’s reusable for any serialized property.

// Assets/Scripts/Editor/NoFoldoutDrawer.cs

using UnityEngine;
using UnityEditor;

// Can set as a custom property drawer for any number of types
[CustomPropertyDrawer(typeof(MyClassA))]
[CustomPropertyDrawer(typeof(MyClassB))]
public class NoFoldoutDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        property.Next(true); // get first child of your property
        do
        {
            EditorGUI.PropertyField(position, property, true); // Include children
            position.y += EditorGUIUtility.singleLineHeight + 2;
        }
        while (property.Next(false)); // get property's next sibling
    }

    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        property.Next(true);
        float result = 0;
        do
        {
            result += EditorGUI.GetPropertyHeight(property, true) + 2; // include children
        }
        while (property.Next(false));
    }
}