Prefix label not showing up in custom inspector

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 {

}

2670638--188478--prefixlabel_bug.png

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.

It appears to be a bug with PrefixLabel. You can however use GUILayout.TextField instead of GUILayout.Label as a workaround until it gets fixed.

Example:

GUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("First label");
GUILayout.TextField("1", "Label");
GUILayout.EndHorizontal();

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.

2670664--188481--labelinsteadofprefixlabel.png

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 ;-))

2670664--188488--fieldlabelinsteadoflabel.png

...
GUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("First label");
EditorGUILayout.LabelField("1");
GUILayout.EndHorizontal();
...

Erm… why not simply

...
EditorGUILayout.LabelField("First label", "1");
...

Anyway, I still wonder if the strange behavior showed above is a bug…

Quick! Download 5.4 and see if it still doesn’t work. Maybe you can get entered into the sweepstakes. http://forum.unity3d.com/threads/unity-5-4-beta-sweepstakes.400686/