Skip to content

Instantly share code, notes, and snippets.

Last active January 20, 2023 07:18
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Fix the display name when serializing property backing fields in Unity.
using UnityEngine;
/// <summary>
/// Use this attribute in combination with a [SerializeField] attribute on top of a property to display the property name. Example:
/// [field: SerializeField, UsePropertyName]
/// public int number { get; private set; }
/// </summary>
public class UsePropertyNameAttribute : PropertyAttribute
using UnityEngine;
using UnityEditor;
public class UsePropertyNameAttributeDrawer : PropertyDrawer
// TODO Make useful for array properties
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
if ("k__BackingField"))
EditorGUI.PropertyField(position, property, label, true);
private static void FixLabel(GUIContent label)
var text = label.text;
var firstLetter = char.ToUpper(text[1]);
label.text = firstLetter + text.Substring(2, text.Length - 19);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment