Changing Inspector's Serialized Property Label (With Code Sample)

I’ve been making progress with one of my first editor extensions / tools for my own personal use and perhaps asset store uploading. It works decently well, but I have a simple question… First, the code.

using UnityEngine;
using UnityEditor;
using System.Collections;

[CustomEditor(typeof(StandardBrush))]
public class StandardBrushINS : Editor 
{
	private SerializedObject standardBrush;
	private SerializedProperty width;
	private SerializedProperty length;
	private SerializedProperty height;

	void OnEnable()
	{
		StandardBrush tempTarget = (StandardBrush)target;
		tempTarget.GetComponent<MeshFilter>().hideFlags = HideFlags.HideInInspector;
		tempTarget.GetComponent<MeshRenderer> ().hideFlags = HideFlags.HideInInspector;
		standardBrush = new SerializedObject (target);

		width = standardBrush.FindProperty ("userDesiredWidth");
		length = standardBrush.FindProperty ("userDesiredLength");
		height = standardBrush.FindProperty ("userDesiredHeight");
	}

	public override void OnInspectorGUI () 
	{
		EditorGUIUtility.LookLikeControls();
		standardBrush.Update ();
		EditorGUILayout.PropertyField (width);
		EditorGUILayout.PropertyField (length);
		EditorGUILayout.PropertyField (height);
		standardBrush.ApplyModifiedProperties();
	}
}

So this code works, it updates the properties of the target in real time. Perfect. However, I have an issue with the SerializedProperty’s labels. They inherit a label next to the field that is essentially the name of the variable. In this case, “User Desired Width/Length/Height” appear next to each field. This is redundant for the client as the “User Desired” naming convention is used mostly to make code more legible (as I do various checks between the User Desired value and the Current value.)

If this were a EditorGUILayout.FloatField, I would be able to put in my desired “label” as a string before the target float variable (i.e. EditorGuiLayout.FloatField(“width”, target.userDesiredWidth) .) Is there an equivalent for SerializedProperty?

You can create a new GUIContent to show a different label as follows:

EditorGUILayout.PropertyField(serializedObject.FindProperty("myVariable"), new GUIContent("aDifferentLabel"));