SpawnPools can also be iterated through as a List of Transforms where only spawned (active) instances are available in the list.
In the following example, all active instances of a SpawnPool "Enemies" are despawned:
Here is another way to iterate until all are despawned. This is from the example files which you can download from the documentation home page. This uses a co-routine which will not only despawn everything, but will do it one at a time ever X seconds (You would still need to start the co-routine as shown in the Unity Documentation).
This version has the following points of interest:
/// Despawn an instance every X seconds
private IEnumerator Despawner()
// Create a short reference to the pool
SpawnPool pool = PoolManager.Pools["Enemies"];
while (pool.Count() > 0)
// Despawn the last instance (like dequeue in a queue because
// Despawn() will also remove the item from the list, so the list
// is being changed in-place.)
Transform instance = pool[pool.Count - 1];
this.pool.Despawn(instance); // Internal count--
yield return new WaitForSeconds(1); // Runs every 1 second
For more regarding using a SpawnPool as a list, continue on to "Copy List of Spawns"...
Example Patterns >