Why is there so much empty space with BeginHorizontal

The code is pretty straightforward:

EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);

SerializedProperty minProperty = def.FindPropertyRelative("rangeMin");
SerializedProperty maxProperty = def.FindPropertyRelative("rangeMax");
EditorGUILayout.LabelField("Min/Max:", GUILayout.Width(90));
EditorGUILayout.PropertyField(minProperty, GUIContent.none);
EditorGUILayout.PropertyField(maxProperty, GUIContent.none);

EditorGUILayout.EndHorizontal();

137966-spacing.jpg

Because the inspector isn’t meant to be use with the layout system in the first place. If you create a custom editor you can. However for example in a property drawer the layout event isn’t even issued. So the inspector usually uses somewhat “fix” rects to layout your controls. By default there’s only one control per line.

For all the nesting stuff Unity uses the EditorGUI.indentLevel to control how much a certain control needs to be indented. Note that Unity actually increases the indentLevel before drawing the children and decrement it afterwards. If you want to draw several things in a line you only want to use the original indent leven for the first element. For the others you may want to set the indentLeven to 0. Though you should backup the old indent leven and restore it when you’re done.

Do you actually write a custom editor or a propertydrawer? Your case seems to be a perfect candidate for a propertydrawer Though as i said you would need to use normal GUI / EditorGUI stuff as the layout system usually isn’t used in the inspector.

In addition to the indentLevel there’s also the fieldWidth setting which controls the fix spacing between the label on the left and the value on the right