- Home /
EditorGUILayout.ObjectField redundant space between label and object field?
This pretty much says it all:
Look at all that redundant space between the label and the field. It looks so stupid. How to get rid of it? How to make it more compact?
Code:
public override void OnInspectorGUI()
{
var use = target as SingleItemUse;
GUILayout.Label("Item entry", EditorStyles.boldLabel);
GUIHelper.HorizontalBlock(() =>
{
use.entry.placement = EditorGUILayout.ObjectField("Placement", use.entry.placement, typeof(Transform), false) as Transform;
use.entry.item = EditorGUILayout.ObjectField("Item", use.entry.item, typeof(Item), false) as Item;
});
}
Thanks for any help.
Answer by ArkaneX · Feb 05, 2014 at 09:22 PM
Hi vexe :)
You can use EditorGUIUtility.labelWidth to control the space reserved for label. Changing it before calling each EditorGUILayout.ObjectField allows to set different widths for different labels.
Arkane for the save! - Thank you dear :) - However, I assume I have to cache the original width to restore later once I'm done, so that I don't affect preceding labels right?
Thx :)
You can cache and reassign original value, or (according to documentation) you can set it to 0 to restore default value.
Awarded, m8. Additionally, might be trivial, but there is also "fieldWidth" :D
Thank you for the answer. I know it was a while ago, but this just helped me immensely.