FactorableObject
Abstract plain C# object base class for non-Unity instances managed by a ScriptableFactory. Implements IFactorable with a thread-safe instance ID counter and no Unity scene management. Subclass this for pooled pure-logic or data objects that do not need a GameObject or Transform.
Definition
Namespace: Paragon.Core.ScriptableFactory Assembly: Paragon.dll
[Serializable]
public abstract class FactorableObject : ParagonObject, IFactorableInherits: ParagonObject (implements IDisposable, IDebugObject) Implements: IFactorable
Generic Variant
[Serializable]
public abstract class FactorableObject<TData> : FactorableObject, IFactorable<TData>
where TData : FactorableDataImplements additionally: IFactorable<TData>
Remarks
FactorableObject is the lightweight alternative to FactorableBehaviour. It extends ParagonObject (a [Serializable] C# class with IDisposable and debug support) and adds factory lifecycle management. Since there is no GameObject, spawn/despawn are purely state transitions — no activation, parenting, or scene manipulation.
Instance IDs
Unlike Unity objects, plain C# objects have no built-in GetInstanceID(). FactorableObject uses a static Interlocked.Increment counter to assign unique IDs during OnInstantiate(), ensuring thread safety.
Destruction
FactorableObject.Destroy() calls the base ParagonObject.Destroy(), which triggers OnDestroy() and IDisposable.Dispose(). The OnDestroy() override auto-despawns if still spawned and notifies the factory.
Quick Lookup
Create a pooled C# object
Subclass FactorableObject, override OnSpawn()
Add data initialization
Subclass FactorableObject<TData>, override InitializeData(TData)
Return to pool from self
Call Despawn()
Permanently destroy
Call Destroy()
Check if active
Read IsSpawned
Get unique ID
Call GetInstanceID()
Setup on first creation
Override OnInstantiate()
Properties
IsSpawned
Returns true while the object is spawned and active.
Methods
Despawn
Returns this object to its owning factory's pool. No-op if the object has no factory reference.
Destroy
Permanently destroys this object. Calls ParagonObject.Destroy(), which triggers OnDestroy() and disposes resources.
GetInstanceID
Returns the unique instance ID assigned during OnInstantiate(). Uses a thread-safe static counter.
Returns: Unique integer identifier for this instance.
Extension Points
Optional Overrides
OnInstantiate()
Factory creates instance (once)
One-time setup, allocate resources
OnSpawn()
Object activated from pool
Initialize per-spawn state
OnDespawn()
Object returned to pool
Reset state, release per-spawn resources
OnDestroy()
Object permanently destroyed
Final cleanup (auto-despawns if still spawned)
Required Overrides (Generic Variant)
InitializeData(TData data)
Configure object from data record (abstract in FactorableObject<TData>)
Implementation Requirements
When subclassing FactorableObject, you MUST:
Mark the class with
[Serializable]for factory serialization support
When subclassing FactorableObject<TData>, you MUST additionally:
Override
InitializeData(TData data)(abstract)
You SHOULD:
Perform expensive allocations in
OnInstantiate()(runs once, not per spawn)Reset all mutable state in
OnDespawn()for clean pool re-useCall
base.OnDestroy()if you overrideOnDestroy()
You SHOULD NOT:
Rely on Unity lifecycle callbacks (
Awake,Start,Update) — this is a plain C# objectCreate instances with
newoutside the factory — the lifecycle hooks will not be called
Common Pitfalls
Double-spawn assertion OnSpawn() asserts if IsSpawned is already true. Ensure every spawn has a matching despawn before re-spawning.
Double-despawn assertion OnDespawn() asserts if IsSpawned is false. Guard against calling Despawn() multiple times.
OnDestroy assertion differs from FactorableBehaviour FactorableObject.OnDestroy() (the explicit IFactorable.OnDestroy() implementation) asserts if IsSpawned is true — it expects the object to have been despawned first. However, the protected override OnDestroy() auto-despawns before notifying the factory, so this is handled automatically when destruction goes through the proper path.
No Unity lifecycle FactorableObject is not a MonoBehaviour. There is no Update(), Awake(), Start(), or coroutine support. If you need frame-based updates, use FactorableBehaviour instead.
Examples
Pooled Data Object
Data-Driven Logic Object
See Also
IFactorable — interface this class implements
FactorableBehaviour — MonoBehaviour alternative (scene objects)
FactorableScriptableObject — ScriptableObject alternative
Factorable Object — subsystem overview
FactorableData — data records for the generic variant
Last updated