Code Reference‎ > ‎SpawnPool‎ > ‎

.CreatePrefabPool()

void CreatePrefabPool(Transform prefab)    

Description
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.
     PoolManager.Pools["Enemies"].CreatePrefabPool(prefabPool);
     
     // Later, just use as normal...
     PoolManager.Pools["Enemies"].Spawn(enemyPrefab);