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 IFactorable

Remarks

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

Goal
How

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.

Parameter
Type
Description

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

circle-exclamation

If you must implement directly, you MUST:

  1. Store the IScriptableFactory reference from OnInstantiate()

  2. Track IsSpawned state across OnSpawn() / OnDespawn() transitions

  3. Assert against double-spawn and double-despawn

  4. Route Despawn() through the factory (not directly to OnDespawn())

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().

Parameter
Type
Description

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

circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated