- Home /
Property field without Header
Hello, I'm really stuck. I'm trying to make this to work for hours but no solution online so far gives me even working result or the explanations of which were all over my head
What i have is a Script, that wants to display the properties of a child it has - In this case CapsuleCombatComponent , so it is easy to configure from top level. The problem I'm facing is that om the said scripts there are headers like [Header("Config")] which creates double header for me, and im looking for way to have EditorGUILayout.PropertyField( prop ); just to display the property without those things.
public override void OnInspectorGUI( )
{
DrawDefaultInspector( );
CapsuleCombatComponent CombatComponent = m_Shell.GetComponentInChildren<CapsuleCombatComponent>();
if ( CombatComponent != null )
{
EditorGUILayout.Space( );
EditorGUILayout.LabelField( "Combat Component Config" , EditorStyles.boldLabel );
SerializedObject component = new SerializedObject(CombatComponent);
if ( component != null )
{
SerializedProperty prop = component.GetIterator();
while ( prop.NextVisible( true ) )
{
if ( prop.name != "m_Script" && ( prop.type == "float" || prop.type == "int" ) )
{
EditorGUILayout.PropertyField( prop );
}
}
prop.Reset( );
}
component.ApplyModifiedProperties( );
}
}
Answer by Sethur · Jun 21, 2021 at 06:48 PM
You can simply pass GUIContent.none
to EditorGUILayout.PropertyField() to suppress rendering of a field header:
[...]
if ( prop.name != "m_Script" && ( prop.type == "float" || prop.type == "int" ) )
{
EditorGUILayout.PropertyField( prop, GUIContent.none );
}
[...]
Oh, thank you! That totally worked and I combined it with:
EditorGUILayout.BeginHorizontal( );
EditorGUILayout.LabelField( prop.displayName );
EditorGUILayout.PropertyField( prop , GUIContent.none );
EditorGUILayout.EndHorizontal( );