IFactorable
Interface defining the lifecycle contract for objects managed by a ScriptableFactory. All factorable objects must implement spawn/despawn hooks, self-despawn, and self-destroy capabilities. The factory calls lifecycle methods in a specific order; implementations should not call these directly.
Definition
Namespace: Paragon.Core.ScriptableFactory Assembly: Paragon.dll
public interface IFactorableRemarks
IFactorable is the core contract between a factory and its managed objects. The factory owns the lifecycle — it calls OnInstantiate(), OnSpawn(), OnDespawn(), and OnDestroy() at the appropriate times. The object itself exposes Despawn() and Destroy() for self-initiated cleanup (e.g., a projectile despawning itself on impact).
The three abstract base classes (FactorableBehaviour, FactorableObject, FactorableScriptableObject) implement this interface using explicit interface implementation, then expose protected virtual methods for subclasses to override. You should not implement IFactorable directly — always subclass one of the base classes.
Quick Lookup
Check if object is active
factorable.IsSpawned
Return object to pool
factorable.Despawn()
Permanently remove object
factorable.Destroy()
Get unique ID
factorable.GetInstanceID()
Properties
IsSpawned
Returns true when the object has been spawned and has not yet been despawned or destroyed.
Methods
OnInstantiate
Called by the factory immediately after creating the instance. Sets up the factory reference and initial state. Do not call directly.
factory
IScriptableFactory
The factory that owns this object
OnSpawn
Called by the factory when the object is activated from the pool. Do not call directly.
OnDespawn
Called by the factory when the object is returned to the pool. Do not call directly.
OnDestroy
Called by the factory when the object is permanently removed from the pool. Do not call directly.
Despawn
Self-initiated despawn. The object requests its owning factory to return it to the pool. Safe to call from game code.
Destroy
Self-initiated destruction. Permanently removes the object. Safe to call from game code.
GetInstanceID
Returns a unique identifier for this instance. For FactorableBehaviour and FactorableScriptableObject, delegates to Unity's GetInstanceID(). For FactorableObject, uses a thread-safe static counter.
Returns: Unique integer identifier for this instance.
Implementation Requirements
Do not implement IFactorable directly. Always subclass one of the three provided base classes. They handle factory reference management, IsSpawned state tracking, assertion guards, and Unity-specific teardown.
If you must implement directly, you MUST:
Store the
IScriptableFactoryreference fromOnInstantiate()Track
IsSpawnedstate acrossOnSpawn()/OnDespawn()transitionsAssert against double-spawn and double-despawn
Route
Despawn()through the factory (not directly toOnDespawn())
IFactorable<TData>
Generic extension of IFactorable that adds data initialization for data-driven factory variants.
Definition
Inherits: IFactorable Type Constraint: TData : FactorableData
Methods
InitializeData
Called by the factory to configure the object with variant data before spawning. Typically invoked between OnInstantiate() and OnSpawn().
data
TData
Data record to initialize from (may be a copy or shared instance depending on factory configuration)
Remarks
The generic base classes (FactorableBehaviour<TData>, FactorableObject<TData>, FactorableScriptableObject<TData>) implement this interface with explicit interface implementation and expose a protected abstract void InitializeData(TData data) method for subclasses to override.
Common Pitfalls
Double-spawn assertion Calling OnSpawn() on an already-spawned object triggers Debug.Assert. The factory guards against this, but ensure external code does not manipulate spawn state directly.
Despawn without factory Despawn() is a no-op if the object has no factory reference (e.g., manually instantiated outside the factory system). The object will not return to any pool.
Destroy before despawn FactorableBehaviour and FactorableScriptableObject assert if OnDestroy() is called while IsSpawned is true. The base classes handle this by auto-despawning in their OnDestroy() override, but be aware of the ordering requirement.
See Also
Factorable Object — subsystem overview with base class selection guide
FactorableBehaviour — MonoBehaviour implementation
FactorableObject — plain C# object implementation
FactorableScriptableObject — ScriptableObject implementation
FactorableData — data records used with
IFactorable<TData>
Last updated