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, IFactorable

Inherits: ParagonScriptableObjectSerializedScriptableObject Implements: IFactorable

Generic Variant

public abstract class FactorableScriptableObject<TData> : FactorableScriptableObject, IFactorable<TData>
    where TData : FactorableData

Implements additionally: IFactorable<TData>

Remarks

FactorableScriptableObject occupies the middle ground between FactorableBehaviour (full GameObject) and FactorableObject (plain C# object). It provides:

  • Odin serialization via SerializedScriptableObject for complex type support

  • Unity asset semantics — instances can be inspected in the editor, referenced by other assets

  • No scene presence — no Transform, no GameObject activation/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

Goal
How

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

Method
Called When
Purpose

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)

Method
Purpose

InitializeData(TData data)

Configure object from data record (abstract in FactorableScriptableObject<TData>)

Implementation Requirements

When subclassing FactorableScriptableObject, you MUST:

  1. Keep the class concrete (non-abstract) if it will be instantiated by a factory

When subclassing FactorableScriptableObject<TData>, you MUST additionally:

  1. 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-use

  • Use Odin serialization attributes for complex Inspector-visible fields

You SHOULD NOT:

  • Use ScriptableObject.CreateInstance<T>() directly — the factory handles instantiation

  • Assume OnDestroy() timing — Unity's destruction order is undefined during application quit

  • Store references to scene objects without null-checking — ScriptableObjects outlive scenes

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation
circle-exclamation

Examples

Pooled Status Effect

Data-Driven ScriptableObject

See Also

Last updated