How do I get indentLevel to work with Buttons?

So I want to indent some buttons in my Editor class for my custom inspector but when I do:

EditorGUI.indentLevel++;
if (GUILayout.Button("Example"))) {
    // Unrelated code
}
EditorGUI.indentLevel--;

Nothing changes, I assume it’s because the button is from the GUILayout class and the indentLevel is from the EditorGUI class so what exactly am I supposed to do to get the effect I’m looking for?

1 Like

You can use GUILayout.BeginHorizontal() and GUILayout.Space().

See:

3 Likes

Got it working perfectly with this thanks! For anybody else needing this 15 pixels is how much each indent is.

1 Like

You can use the current value of EditorGUI.indentLevel to set the left margin on a GUIStyle which is then applied to your button:

GUIStyle buttonStyle = new GUIStyle(EditorStyles.miniButton);
buttonStyle.margin = new RectOffset(EditorGUI.indentLevel * 15, 0, 0, 0);
if (GUILayout.Button("Button Label", buttonStyle)) {...}
2 Likes