Hello, I was doing some editor scripting when I stumbled upon this strange bug when adding two or more prefix label in a row. Here is a code to reproduce the problem and the result I get.
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(testscript))]
public class testscriptInspector : Editor
{
public override void OnInspectorGUI()
{
GUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("First label");
GUILayout.Label("1");
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("Second label");
GUILayout.Label("2");
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("Third label");
GUILayout.Label("3");
GUILayout.EndHorizontal();
}
}
public class testscript : MonoBehaviour {
}
Does anyone have already had this kind of behaviour? Is this a bug or am I doing something wrong? It does that from 5.0.0 to 5.4b17 as far as I can tell.
Thank you! You put me on the right track… explanation below…
You previously stated (before you edited your answer) that EditorGUILayout might want another EditorGUILayout control after it. It makes sense. I always assumed this had no importance as documation states we can mix and match functions from GUI and GUILayout so I extrapolated that to EditorGUILayout and GUILayout… that’s not the same thing obviously.
Actually the reason I chose to use EditorGUILayout.PrefixLabel was to let Unity figure out the right size itself instead of having to correct the situation you see below when using GUILayout.Label.
So… I searched a bit more and found EditorGUILayout.LabelField which does seem to appreciate PrefixLabel’s company more… (which is a better alternative to TextField by the way ;-))