Code Reference‎ > ‎


class PrefabPool

PrefabPools are used internally by a SpawnPool to manage per-prefab options and instances.  See these links for more information to get a better idea of what PrefabPools are.
    See 'Per-Prefab Options' for information about each of the settings/options available.
    See SpawnPool.CreatePrefabPool() for usage information 

If you do  need access to a PrefabPool, use the SpawnPool.prefabPools dictionary.

Class Members

Here are members not described in the inspector documentation linked above.

Turn this ON to activate the culling feature for this Pool.
Use this feature to remove despawned (inactive) instances from the pool if the size of the pool grows too large.
DO NOT USE THIS UNLESS YOU NEED TO MANAGE MEMORY ISSUES! This should only be used in extreme cases for memory management. For most pools (or games for that matter), it is better to leave this off as memory is more plentiful than performance. If you do need this you can fine tune how often this is triggered to target extreme events.
A good example of when to use this would be if you you are Pooling projectiles and usually never need more than 10 at a time, but then there is a big one-off fire-fight where 50 projectiles are needed. Rather than keep the extra 40 around in memory from then on, set the 'Cull Above' property to 15 (well above the expected max) and the Pool will Destroy() the extra instances from the game to free up the memory.
This won't be done immediately, because you wouldn't want this culling feature to be fighting the Pool and causing extra Instantiate() and Destroy() calls while the fire-fight is still going on. See
"Cull Delay" for more information about how to fine tune this.
The number of TOTAL (spawned + despawned) instances to keep.
The amount of time, in seconds, to wait before culling. This is timed from the moment when the Queue's TOTAL count (spawned + despawned) becomes greater than 'Cull Above'. Once triggered, the timer is repeated until the count falls below 'Cull Above'.
The maximum number of instances to destroy per this.cullDelay
A read-only list of instances currently in a despawned state
limitAmountThis is the max number of instances allowed if 'limitInstances' is ON.
FIFO stands for "first-in-first-out". Normally, limiting instances will stop spawning and return null. If this is turned on (set to true) the first spawned instance will be despawned and reused instead, keeping the total spawned instances limited but still spawning new instances.
limitInstancesLimits the number of instances allowed in the game. Turning this ON means when 'Limit Amount' is hit, no more instances will be created (unless FIFO is used). CALLS TO SpawnPool.Spawn() WILL BE IGNORED, and return null!
This can be good for non-critical objects like bullets or explosion Flares. You would never want to use this for enemies unless it makes sense to begin ignoring enemy spawns in the context of your game.
logMessagesPrints information during run-time to make debugging easier. This will be set to true if the owner SpawnPool is true, otherwise the user's setting here will be used
prefabA cached reference to the prefab's Transform
prefabGOA cached reference to the prefab's GameObject
The number of instances to preload
Displays the 'preload over time' options
The number of frames it will take to preload all requested instances
The number of seconds to wait before preloading any instances
spawnedA read-only list of instances currently in a spawned state
A reference back to the SpawnPool which owns this PrefabPool
SpawnNew()Forces a new instance to be created (runs Unity's Instanciate(). Useful for creating custom preloading scripts.
totalCountReturns the total count of instances in the PrefabPool