Lifetime & scopes

Options can be added and removed at any time - the panel follows immediately. Three tools decide who does the removing: handles, owner objects, and scopes.

Handles

Add returns an OptionHandle - keep it when you need to remove the option later or push a refresh:

EventCheats.cs
using DebugMD;

OptionHandle _handle;

void EnableEventCheats()
{
    _handle = DMD.Options.Add(
        Option.Button("Complete Event", () => _event.ForceComplete()));
}

void DisableEventCheats()
{
    _handle.Remove();  // safe to call more than once
}

What a handle gives you:

MemberMeaning
Remove()Removes the option from the panel. Calling it again is a no-op.
IsRegisteredWhether the option is still in the registry.
NotifyChanged()Pushes an immediate value refresh to the option's widget. Never required - visible widgets re-read your getters on their own - but useful right after a burst of changes.
OptionThe option the handle controls.
Pin() / Unpin() / IsPinned Controls the option's floating widget - see Pin to screen.

Owner-bound options

Pass a UnityEngine.Object as the second argument to Add and the option's lifetime follows it: when the owner is destroyed - explicitly or by a scene unload - the option is removed for you.

BossCheats.cs
using DebugMD;
using UnityEngine;

public class BossCheats : MonoBehaviour
{
    private void Start()
    {
        // Gone automatically when this component's GameObject dies.
        DMD.Options.Add(
            Option.Button("Kill Boss", () => GetComponent<Boss>().Die()),
            this);
    }
}

Destroyed owners are swept about twice a second, so removal is near-immediate rather than same-frame. If an option must disappear on an exact frame, remove it through its handle instead.

Scopes

A scope batches registrations so they can all be removed with one call. Everything added through the scope - shorthands included - is removed together when the scope is disposed. This is the tool for scene-specific cheat sets and live-ops event windows:

ArenaSceneCheats.cs
using DebugMD;
using UnityEngine;

public class ArenaSceneCheats : MonoBehaviour
{
    private OptionsScope _scope;

    private void Awake()
    {
        _scope = DMD.Options.CreateScope();
        _scope.AddButton("Win Round", () => _arena.WinRound());
        _scope.AddToggle("Infinite Stamina", () => _cheat, v => _cheat = v)
            .InTab("Arena");
    }

    private void OnDestroy()
    {
        _scope.Dispose();  // removes every option added above
    }
}

Scopes and owners compose with everything else: a scoped option still supports tabs, rows, pinning and all fluent modifiers. Options in a disposed scope vanish from the panel - and from the pinned dock - immediately.

The rules

  • One registration per instance. Adding the same Option object twice throws InvalidOperationException. Create a fresh option if you need the same cheat in two places.
  • Main thread only. The registry is not thread-safe; register and remove from the main thread.
  • Sessions start empty. Registrations do not carry over between play sessions - even with domain reload disabled, the registry is cleared when a session ends. Register on startup, every run.
  • The panel keeps up. Adds and removals appear in the open panel immediately; there is no rebuild step and no need to reopen anything.
Clip pending - switching scenes while the panel is open: the arena tab's options disappear as the scene's scope disposes
Scene-scoped options leaving the panel the moment their scene unloads.