Object pooling, your experience and best asset to use?

Hi!

I was using Prime31’s Recycler but i was wondering is there anything else better and what you guys use?
I also didn’t have any luck with using pooling with particles since they don’t properly start and stop (i have some nested particle systems and the way recycler was working i couldn’t make it work right)

i would like some general solution that i might develop to use in all projects (enemies, collectables,sound,ui elements, etc…)

any ideas are appreciated!

Haven’t used Prime31’s solution so far since I was sticking to Path-o-logical’s PoolManager. Easy to use, does exactly what it’s supposed to do. Guess pooling is not too hard to implement on your own if you got any special needs, but why invent another wheel… :wink:

1 Like

I just wrote my own only took a few hours and supports everything I need.

1 Like

Agree with cmcpasserby. Just knock out your own. I threw one together for my retro style platform game project in about 30 minutes.

All of this object pooling stuff is nothing new. It is just allocating objects up front, deactivating them and storing them for use later one. We were doing it 30 years ago with arrays. The nice thing with Unity3D is you can make it so you can customize it right in the inspector. So, instead of hard-coding the quantities of objects in your code you can expose variables such as MaxBullets, MaxEnemies and so forth so you can adjust the values right in the inspector.

Start with a fairly high number. Then it is just a matter of play testing and continually dropping that number down until you notice some failures to generate an object (just use Debug.Log to log whenever the pool fails to return something).

Finally, you can also make it so your object pool can dynamically grow. I use Lists instead of arrays.

Ya I use lists as well, and have it log warnings if the game tries to spawn something when there isn’t enough left in the pool. Can also in that case just instantiante and add to the pool.

I also support multiple pools so I can easily kill off a whole pool.

Personally I use Queue<>. An item is only in the queue when its available for use… makes it nice and fast without any requirement to search a list for an item thats available.

no item in queue. create new one. eventually it reaches a maximum and wont instantiate further.

The Queue is managed as the value of a dictionary.

I agree with Glockenbeat – no need to reinvent the wheel. An hour saved is an hour saved – and often two hours saved, including debugging and maintaining the code, maybe more if you then find that you need to add more-advanced features that others have already battle-tested in their own pooling products.

It depends on what you need to pool. If you really absolutely need the lightest and most feature-bare pooler, maybe it would be best to write your own. If you’re using a product like Core GameKit to spawn objects, might as well use its bundled pool manager, since it’s designed to work well with Core GameKit. I’ve also used Path-o-Logical’s PoolManager, and it has some really useful features beyond a basic List<> or Queue<>.

I built my own. When I need an object that I know I need to pool I just call a function that checks to see if there is one in the pool, if so grab it, if not then make a new one. It runs pretty smoothly for me. If you want to see the code let me know and ill post it.

1 Like