Dynamic Pooling System - How could I make this?

I am trying to create a dynamic pooling system, so in other words a script that will enabled and disable objects( recycling ) but over time change the speed at which objects are recycled. What is a good way of accomplishing this?, At first I thought take the route that only made sense to me which was creating a counter which counts from 0 to infinity, and when it hits certain points create a brand new pool system which is slightly faster than the one before. But I feel like there is a much more easier way of doing this. I am just not sure how, any ideas?

Separate your concerns out. Make a generic object pool in one script. The spawning and increasing spawn rate should be taken care if by another script that references the object pool.

1 Like

If you’re doing your pooling in a way that this makes sense, you’re probably doing your pooling wrong.

Best practice.

  1. Request Object
  2. Object in pool? return object (remove from pool). Use a queue or a stack.
  3. No Object in pool, Create new and return new.
  4. Object is finished, add to queue.

repeat.

Bonus Points, if you know ahead of time how many you will need over the life of the game, bulk create and add to pool.

Only consideration is that if you stop using objects of type completely you may end up with objects in memory that dont need to be, but you can control the purge yourself.