General pooling question

I have a general question about pooling. I have a simple 2D game that spawns random stars (different types) that you collect, random enemies that you avoid, and random health points that you collect. Some levels use different types that fit the world (eg. ice-world, summer, etc.)

Currently, the prefabs spawn randomly using a switch and are destroyed once they reach a boundary outside of the scene. This seems like a great opportunity to use pooling but I don’t know the best way to use it.

  1. Should I create a unique pool and instance for each unique prefab and then switch between them randomly in the spawner?


  1. Should I look into creating pools of stars that has all of the stars in it and randomly selects from the list, enemies with all the enemy types in it, etc?


  1. Is there another option?

I’m brand new to pooling and have been researching all morning but I’m confused about how to approach this, given the random nature of what I want to do.

Also, do I need new instances for each pool if I go with option #1?

Thank you,


Pooling effectiveness depends on the case. If you are using lots of gameobjects then pooling them will be more efficient than instantiate/destroy. That being said, your option 1 is viable in which you have a pool for each object type and after you random it you have a way to pick the appropriate pool to give you an available object.

For your option 2, I am not sure how you can implement the randomness in a complete pool of gameobjects, in order to enforce the probabilities you want. For example, if you throw all kinds of stars in a single pool of say 100 and you have 10 of them in use, the random generator will have to pick something from the remaining 90? Therefore making the problem a bit more complex.