Skip to content

Inspector Attributes

OxHeart provides lightweight inspector attributes that work out of the box — no third-party inspector extension required.

[OxButton]

Place [OxButton] on any parameterless instance method of a MonoBehaviour or ScriptableObject to render a clickable button in the Unity Inspector.

using OxHeart.Core.Inspector;
using UnityEngine;

public class EnemySpawner : MonoBehaviour
{
    [SerializeField] private GameObject prefab;
    [SerializeField] private int waveSize = 5;

    [OxButton("Spawn Wave")]
    public void SpawnWave()
    {
        for (int i = 0; i < waveSize; i++)
            Instantiate(prefab, Random.insideUnitSphere * 10f, Quaternion.identity);
    }

    [OxButton]
    public void ClearAll()
    {
        // Method name is nicified automatically: "Clear All"
        foreach (var enemy in FindObjectsByType<Enemy>(FindObjectsSortMode.None))
            Destroy(enemy.gameObject);
    }
}

Features

  • Custom labels. Pass a string: [OxButton("My Label")]. Without one, the method name is nicified (ResetHealth → Reset Health).
  • Private methods. [OxButton] works on private and protected methods, not only public.
  • Return values. Any return value is silently discarded — the button invokes the method for its side effects.
  • Undo. Every button click records an Undo snapshot, so changes are reversible with Ctrl+Z.
  • Multi-object editing. When multiple objects are selected, the button invokes the method on each one.
  • Inheritance. Buttons declared on a base class appear on derived classes.

How it works

OxHeart registers a fallback CustomEditor (with isFallback = true) for MonoBehaviour and ScriptableObject. Unity uses a fallback editor only when no other CustomEditor exists for the type, so existing custom editors in your project or in OxHeart itself are never affected.

Methods with parameters

Methods that take parameters are silently skipped — only parameterless methods produce buttons. If you need parameterized inspector buttons, consider a dedicated inspector extension library such as Odin Inspector, NaughtyAttributes, or Tri Inspector.

Compatibility with other inspector libraries

If your project also uses Odin Inspector, Alchemy, NaughtyAttributes, or Tri Inspector, those libraries register their own fallback editors. When multiple fallback editors exist, Unity picks one — which may not be OxHeart's. In that case, use the other library's equivalent attribute (typically [Button]) instead of [OxButton].

Sample

See Samples~/Scripts/14_OxButtonSample.cs for a working example with public, private, labeled, and default-labeled buttons.