One of the overloads (versions) of SpawnPool.Despawn() takes a time, in seconds, to delay despawn. Here is a simple way to spawn something that will automatically despawn in 2 seconds: Assume we have an "Enemies" pool and a reference to a prefab's Transform 'myPrefab'. // Spawn an instance and store it
Transform instance = PoolManager.Pools["Enemies"].Spawn(myPrefab); // Call Despawn immediately, but with a 2 second delay PoolManager.Pools["Enemies"].Depawn(instance, 2); ParticleEmitter Warning: This pattern is tricky when used with a ParticleEmitter because passing a ParticleEmitter to Spawn() will automatically use the auto-despawn feature which listens for all particles to die then despawns the instance owning the passed ParticleEmitter. If the despawn timer in the pattern above triggers before the ParticleEmitter's particles all die, then it will just despawn early, but if it triggers after, then you will get an "already despawned" error message. |
Example Patterns >