FactorablePool

Object pool that manages the lifecycle of IFactorable instances for a single factory. Tracks three lists — all pooled objects, active (spawned) objects, and inactive (despawned, reusable) objects — and auto-expands by requesting new instances from the factory when the pool is exhausted.

Definition

Namespace: Paragon.Core.ScriptableFactory Assembly: Paragon.dll

public class FactorablePool

Remarks

FactorablePool is owned internally by ScriptableFactory<TObject> and serves as its object recycling mechanism. The factory delegates lifecycle tracking to this pool: when objects are instantiated, spawned, despawned, or destroyed, the factory calls the corresponding On* methods on the pool.

The pool does not call OnSpawn() or OnDespawn() on the IFactorable objects themselves — that remains the factory's responsibility. The pool only tracks list membership.

Quick Lookup

Goal
How

Get a reusable object

pool.GetObject() — returns inactive object or auto-instantiates

Track new instantiation

pool.OnInstantiate(obj)

Track spawn

pool.OnSpawn(obj)

Track despawn

pool.OnDespawn(obj)

Track destruction

pool.OnDestroy(obj)

Destroy entire pool

pool.Destroy()

Query all objects

pool.GetPool()

Query active objects

pool.GetActiveObjects()

Query inactive objects

pool.GetInactiveObjects()

Properties

Factory

The factory this pool draws from when auto-expanding.

Capacity

Total number of objects in the pool (active + inactive).

Constructor

Parameter
Type
Description

factory

IScriptableFactory<IFactorable>

The factory used to instantiate new objects when the pool is empty

Initializes all three internal lists as empty.

Methods

GetObject

Returns an inactive object from the pool. If no inactive objects are available, calls Factory.Instantiate() to create a new one first.

Returns: An IFactorable instance removed from the inactive list.

circle-exclamation

OnInstantiate

Registers a newly instantiated object. Adds it to both the master pool list and the inactive list.

Parameter
Type
Description

factoryObject

IFactorable

The newly created object

OnSpawn

Moves an object to the active list. Called by the factory when an object is spawned.

Parameter
Type
Description

factoryObject

IFactorable

The spawned object

circle-info

Note that GetObject() removes the object from the inactive list, but OnSpawn() adds it to the active list. Both calls are needed for a complete spawn cycle.

OnDespawn

Moves an object from the active list back to the inactive list for reuse.

Parameter
Type
Description

factoryObject

IFactorable

The despawned object

OnDestroy

Permanently removes an object from all pool tracking lists.

Parameter
Type
Description

factoryObject

IFactorable

The destroyed object

Destroy

Destroys all objects in the pool by calling Factory.Destroy() on each one. Iterates over a copy of the pool list to avoid collection modification during enumeration.

GetPool

Returns all objects in the pool (both active and inactive).

GetActiveObjects

Returns only the currently spawned (active) objects.

GetInactiveObjects

Returns only the despawned (inactive, reusable) objects.

Common Pitfalls

circle-exclamation
circle-exclamation

See Also

  • IScriptableFactory<TObject> — factory interface that owns the pool

  • IFactorable — interface for pooled objects

  • ScriptableFactory<TObject> — concrete factory that uses this pool

Last updated