FactorableScriptableObject
Abstract ScriptableObject base class for asset-like instances managed by a ScriptableFactory. Implements IFactorable without GameObject scene management. Subclass this for pooled objects that need ScriptableObject serialization semantics but not scene presence (e.g., runtime-created data containers, status effects, modifiers).
Definition
Namespace: Paragon.Core.ScriptableFactory Assembly: Paragon.dll
public abstract class FactorableScriptableObject : ParagonScriptableObject, IFactorableInherits: ParagonScriptableObject → SerializedScriptableObject Implements: IFactorable
Generic Variant
public abstract class FactorableScriptableObject<TData> : FactorableScriptableObject, IFactorable<TData>
where TData : FactorableDataImplements additionally: IFactorable<TData>
Remarks
FactorableScriptableObject occupies the middle ground between FactorableBehaviour (full GameObject) and FactorableObject (plain C# object). It provides:
Odin serialization via
SerializedScriptableObjectfor complex type supportUnity asset semantics — instances can be inspected in the editor, referenced by other assets
No scene presence — no
Transform, noGameObjectactivation/deactivation
Like FactorableBehaviour, it uses Object.Destroy(this) for permanent destruction. Like FactorableObject, spawn/despawn are purely state transitions with no scene manipulation.
Destruction Behavior
The OnDestroy() override auto-despawns (if spawned) and notifies the factory before Unity destroys the ScriptableObject instance. The explicit IFactorable.OnDestroy() asserts if the object is still spawned — this guards against factory-side destruction of active objects.
Quick Lookup
Create a pooled ScriptableObject
Subclass FactorableScriptableObject, override OnSpawn()
Add data initialization
Subclass FactorableScriptableObject<TData>, override InitializeData(TData)
Return to pool from self
Call Despawn()
Permanently destroy
Call Destroy()
Check if active
Read IsSpawned
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 ScriptableObject instance via Object.Destroy(this).
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()
Unity OnDestroy callback
Final cleanup (auto-despawns if still spawned)
Required Overrides (Generic Variant)
InitializeData(TData data)
Configure object from data record (abstract in FactorableScriptableObject<TData>)
Implementation Requirements
When subclassing FactorableScriptableObject, you MUST:
Keep the class concrete (non-abstract) if it will be instantiated by a factory
When subclassing FactorableScriptableObject<TData>, you MUST additionally:
Override
InitializeData(TData data)(abstract)
You SHOULD:
Perform expensive setup in
OnInstantiate()(runs once per instance)Reset all mutable state in
OnDespawn()for clean pool re-useUse Odin serialization attributes for complex Inspector-visible fields
You SHOULD NOT:
Use
ScriptableObject.CreateInstance<T>()directly — the factory handles instantiationAssume
OnDestroy()timing — Unity's destruction order is undefined during application quitStore references to scene objects without null-checking — ScriptableObjects outlive scenes
Common Pitfalls
Double-spawn assertion OnSpawn() asserts if IsSpawned is already true. Ensure every spawn has a matching despawn.
Double-despawn assertion OnDespawn() asserts if IsSpawned is false. Guard against calling Despawn() multiple times.
Destroy-while-spawned assertion The explicit IFactorable.OnDestroy() asserts if IsSpawned is true. The protected virtual OnDestroy() handles this by auto-despawning first, but direct calls to IFactorable.OnDestroy() will fail if the object is still spawned.
ScriptableObject persistence Unlike FactorableBehaviour, FactorableScriptableObject instances exist outside the scene. They survive scene loads unless explicitly destroyed. Be mindful of memory if pooling large numbers of ScriptableObject instances.
Examples
Pooled Status Effect
Data-Driven ScriptableObject
See Also
IFactorable — interface this class implements
FactorableBehaviour — MonoBehaviour alternative (scene objects)
FactorableObject — plain C# object alternative
Factorable Object — subsystem overview
FactorableData — data records for the generic variant
Last updated