Skip to content

KeyedPooledObjectCreator

One component that pools many prefabs, each picked by a Key.

Namespace: Jungle.Objects Inherits: PooledCreatorBase → GameObjectCreator → ItemCreator<GameObject> Implements: IItemCreator<GameObject>, IPoolObjectOwner, IKeyedCreator

Overview

Drop your prefabs into the list. Each one gets its own reserve, and spawns under a Key. When you leave the key empty, the first tag on the prefab's Tagger is used, so a folder of tagged prefabs is wired by drag and drop alone.

A Spawn operation picks the pool with its Key field. Use Tag Of Object there to spawn whatever matches the object the run is about: a smelter holding a copper nugget spawns from the pool tagged Copper. When the key source yields several objects, Spawn fires Count times per key, so two held nuggets give two bars. Prewarm takes the same Key, and primes every pool when it is left empty.

For a single prefab, PooledObjectCreator is the simpler choice. Both share the same pooling behaviour.

Properties

Property Type Description
entries List<Entry> Prefab plus optional Key. Empty key falls back to the prefab's first tag.
initialCount int Objects pre-instantiated per prefab on start.
maxCount int Maximum pool size per prefab. 0 for unlimited.
defaultKey Key Pool used by a spawn without a key (plain Spawn, Prewarm, scene restore). Empty means a key is required.
poolParent Transform Parent for inactive objects. Uses this transform if not set.
maxActive int Maximum active objects per prefab. Past it, the oldest is force-returned. 0 for unlimited.
onInitialized ProcessSlot Runs once in play mode, right after the pools are filled.

Methods

Method Description
Create(Key, Action<GameObject>) Acquires from the pool behind the key. Unknown key logs an error and yields null.
Create(Action<GameObject>) Same, using defaultKey. Errors when no default is set.
TryGetPool(Key, out GameObjectPool) The pool behind a key, for counts and ReleaseAll.
Keys Every key this creator can spawn.
KeyOf(GameObject) The key an instance was spawned under. Scene state saves it and restores under the same key.
CreateInOrder(IReadOnlyList<Key>, Action) One spawn per key, reported in order. Used by scene state restore.
Reclaim(GameObject, Action) Returns an instance to the pool it came from.
ReleaseAll() Force-reclaims every active object of every pool.

See Also