- Home /
EditorGUI.PrefixLabel broken?
So I'm following along with a tutorial (https://catlikecoding.com/unity/tutorials/hex-map/part-1/) and am currently on part 4.1 where we make a custom property drawer and for some reason mine just isn't displaying the label no matter what I do. It's half working because the positioning is correct for the information afterwards, but instead of displaying the name of the property, it's just blank.
Here's the code for the property drawer, it's exactly the same as in the tutorial and it worked just fine for him.
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(HexCoordinates))]
public class HexCoordinatesDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
HexCoordinates coordinates = new HexCoordinates(property.FindPropertyRelative("x").intValue,
property.FindPropertyRelative("z").intValue);
position = EditorGUI.PrefixLabel(position, label);
GUI.Label(position, coordinates.ToString());
}
}
The tutorial is a few years old at this point, so I wouldn't be surprised if this is a new bug or it's been deprecated, but even according to the current documentation what I'm doing should work. I tried playing around with some things and confirmed that label.text is "Coordinates" which is what I expect to see instead of nothing. Any ideas? I'm using Unity 2021.1.19f1
Answer by gregsolo · Nov 23, 2021 at 02:12 AM
Adding EditorGUI.LabelField( position, label );
before updating position helped me (Unity 2020.3.23):
EditorGUI.LabelField( position, label );
position = EditorGUI.PrefixLabel(position, label);
GUI.Label(position, coordinates.ToString());
Answer by Jetaddict · Oct 12, 2021 at 08:52 PM
Same manual, same chapter, same concern :-) spent a while looking how to set LabelText.text explicilty, no luck yet. Unity 2020.3.20f1 :-)
Your answer
Follow this Question
Related Questions
Custom brush tool? 0 Answers
Change the alingment of 2 GUILayout Label 0 Answers
Move objects in scene view before running the game 0 Answers
How to make a Custom inspector? 2 Answers