Adding space() to BeginHorizontal() causes extra vertical spacing after certain amount.
I am working on a custom editor for a heirarchy of military unit structure. For each subunit of a given unit I display a new line in the list and indent it by the depth of the unit in the structure. You can see that in the image for more clarity.
I am noticing a behavior with EditorGUILayout.BeginHorizontal() where after applying a certain amount of space on a line there is extra vertical space occuring like something is trying to wrap because of the 'indent'. However, the furthest right thing in the horizontal layout is a GUILayout.FlexibleSpace(). I can't for the life of me find out what is causing the extra padding. When I reduce the indent amount added per line it works as expected with nothing extra vertically. I can determine based on the level and indent added per level that the Space() value is 40.
Here is a simplified script with the EditorGUILayout/GUILayout calls being made. Also note that the call is recursive to handle the subordinate units.
  private void UnitLine(string parent, string unit, int level)
         {
             var unitComp = _unitMap[unit];
             EGL.BeginHorizontal(GL.ExpandWidth(true));
             EGL.Space(level * 10);
             EGL.BeginHorizontal(GUI.skin.box, GL.ExpandHeight(false), GL.ExpandWidth(true));
             var doFoldout = _foldoutOpen.GetValueOrDefault(unit, false);
             
             _foldoutOpen[unit] = EGL.Foldout(doFoldout, "");
             
             if (GL.Button("E"))
             {
                 _activeEditUnit = unit;
             }
 
             if (GL.Button("S"))
             {
                 var newUnit = new UnitComposition
                 {
                     Id = Guid.NewGuid().ToString()
                 };
                 _unitMap[newUnit.Id] = newUnit;
                 _foldoutOpen[newUnit.Id] = false;
                 if (unitComp.Subordinates == null)
                 {
                     unitComp.Subordinates = new List<string>();
                 }
                 unitComp.Subordinates.Add(newUnit.Id);
                 _fs.Units.Add(newUnit);
             }
 
             if (GL.Button("D"))
             {
                 _markedForDelete = unit;
                 _markedForDeleteParent = parent;
             }
             
             GL.Space(10);
             
             EGL.LabelField($"Name: {unitComp.Name}", GL.ExpandWidth(false));
             GL.FlexibleSpace();
             EGL.EndHorizontal();
             EGL.EndHorizontal();
             EGL.Space(3);
             
             if (unitComp.Subordinates is not {Count: > 0} || !_foldoutOpen.ContainsKey(unit) || !_foldoutOpen[unit]) return;
             level++;
             foreach (var subordinate in unitComp.Subordinates)
             {
                 UnitLine(unit, subordinate, level);
             }
         }
Answer by DallasP9124 · Jun 03 at 01:01 AM
Here is an image of what I am seeing.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                