ParagonObject
Abstract base class for non-Unity serializable objects in the Paragon framework. Provides a manual Initialize()/Destroy() lifecycle, automatic debug system registration, and IDisposable support for deterministic cleanup.
Definition
Namespace: Paragon
Assembly: Paragon.dll
[Serializable]
public abstract class ParagonObject : IDisposable, IDebugObjectImplements: System.IDisposable, IDebugObject
Remarks
ParagonObject is the base for any Paragon object that is not a Unity Object (not a MonoBehaviour or ScriptableObject). It provides the same debug registration pattern as ParagonBehaviour but with an explicit Initialize()/Destroy() lifecycle instead of Unity's OnEnable()/OnDisable().
Both ParagonSubsystem and ParagonComponent<T> inherit from this class.
The IDisposable.Dispose() implementation delegates to Destroy(), enabling using statements and integration with disposal patterns.
Quick Lookup
Create and initialize
obj.Initialize()
Destroy and clean up
obj.Destroy()
Use with using
using (var obj = ...) { } — calls Destroy() on dispose
Enable debug rendering
obj.DebugEnabled = true then override OnDebug()
Properties
DebugEnabled
Controls whether OnDebug() is called by the debug system each frame.
Methods
Initialize
Registers the object with the debug system. Subclasses should call base.Initialize() first.
Calls Debug.Register(this) to opt into the per-frame debug loop.
Destroy
Unregisters from the debug system and calls OnDestroy() for subclass cleanup.
Not virtual — cleanup logic goes in OnDestroy().
OnDestroy
Override point for subclass-specific cleanup logic. Called by Destroy().
OnDebug
Override point for debug rendering. Called each frame by the debug system when DebugEnabled is true.
Debug.Register() and Debug.Unregister() are decorated with [Conditional("DEBUG_ENABLED")]. In release builds without that define, registration is a no-op and OnDebug() is never called.
Extension Points
Optional Overrides
Initialize()
Custom initialization — call base.Initialize() first
OnDestroy()
Cleanup on destruction
OnDebug()
Per-frame debug rendering (gizmos, logging)
Implementation Requirements
When subclassing ParagonObject, you MUST:
Call
base.Initialize()if overridingInitialize()— this registers with the debug systemCall
Destroy()when the object is no longer needed — or useIDisposable/using
You SHOULD:
Override
OnDestroy()for cleanup instead of overridingDestroy()Keep
OnDebug()lightweight — it runs every frame when enabled
Common Pitfalls
Destroy is not virtual
Unlike Unity objects, Destroy() on ParagonObject is not virtual. Put cleanup logic in OnDestroy(), not in a Destroy() override.
Dispose calls Destroy
IDisposable.Dispose() calls Destroy(). Do not call both — it will attempt to unregister from the debug system twice.
See Also
ParagonBehaviour — Unity MonoBehaviour base (equivalent for scene objects)
ParagonSubsystem — extends this class for component containers
ParagonComponent<TBehaviour> — extends this class for subsystem components
Last updated