HideLabel - BluePixelDev/utilkit GitHub Wiki

HideLabelAttribute is a custom Unity attribute that hides the label of a serialized field in the Inspector.

Overview

Unity displays field labels by default in the Inspector. This attribute can be used to suppress the label, which is useful for fields where the label would be redundant or clutter the UI.

Features

  • Hides the default label for serialized fields
  • Works with both IMGUI and UIElements inspectors
  • Easily applied via attribute usage

Usage Example

[HideLabel]
[SerializeField] private string noLabelText;

Implementation Details

Class: HideLabelAttribute

  • Inherits from PropertyAttribute
  • Used to tag serialized fields

Class: HideLabelDrawer

  • Custom PropertyDrawer for fields marked with HideLabelAttribute
  • Works in both UIElements and IMGUI inspectors

Editor-Only Compilation

This attribute and its drawer are only compiled and used within the Unity Editor:

#if UNITY_EDITOR
// Editor-only code here
#endif

This ensures it does not affect builds or runtime performance.