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 FactorablePoolRemarks
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
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
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.
Auto-expansion side effect
When no inactive objects exist, GetObject() triggers Factory.Instantiate(), which in turn calls OnInstantiate() on this pool. The newly created object is added to the inactive list and then immediately returned.
OnInstantiate
Registers a newly instantiated object. Adds it to both the master pool list and the inactive list.
factoryObject
IFactorable
The newly created object
OnSpawn
Moves an object to the active list. Called by the factory when an object is spawned.
factoryObject
IFactorable
The spawned object
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.
factoryObject
IFactorable
The despawned object
OnDestroy
Permanently removes an object from all pool tracking lists.
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
GetObject does not call OnSpawn
GetObject() only removes the object from the inactive list and returns it. The caller (typically the factory) must still call OnSpawn() separately to move it to the active list.
OnDespawn does not validate active membership
OnDespawn() removes from activeObjects and adds to inactiveObjects without checking whether the object was actually in the active list. Calling OnDespawn() on an already-inactive object will add a duplicate to the inactive list.
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