Code Reference‎ > ‎SpawnPool‎ > ‎


void CreatePrefabPool(Transform prefab)    

Creates a new PrefabPool in this SpawnPool to allow prefab-specific options, such as preloading.

This function should only be used once and only if you need to use the options or static access later:
  • This functionality is provided through Unity's Inspector so this function is only needed if you need to create a prefab pool, with options AND through scripting.
  • A PrefabPool is created automatically simply by using Spawn() the first time, so, again, even through scripting this function is only needed if you actually need the settings/options. Most of the time the Inspector interface is enough but this is nice to have if a lot of pools need to be managed and drag&drop becomes tedious.

Note on preloading:If preload amount is 0, nothing will be spawned and the return list will be empty, but any other settings will be applied as expected.

     // Create a prefab pool, set culling options but don't need to pre-load any
     PrefabPool prefabPool = new PrefabPool(enemyPrefab);
     prefabPool.preloadAmount = 1;      // Recommended to pre-load at least 1

     prefabPool.cullDespawned = true;
     prefabPool.cullAbove = 40;
     prefabPool.cullDelay = 5;
     prefabPool.cullMaxPerPass = 5;     // This is the default so may be omitted

     prefabPool.limitInstances = false// This is the default so may be omitted
     prefabPool.limitAmount = 0;        // This is the default so may be omitted
     // Enemies is just an example. Any SpawnPool is fine.
     // Later, just use as normal...