New Unity Pooling API with different prefabs

Hi,
i´m checking out the new object pooling api in Unity 2021.
I was wondering how to manage different prefabs in the pool?

For example:
1 Pool for different types of bullets

Greetz
Billy

I’m curious about this as well.

Well it depends on your use case.

You can use the same pool for different prefabs, as long as they all share a common type, for example “Bullet”, but then the pool will return / reused “random” (of course not real random, but you get what I mean) instances and you can’t control which bullet type you get. Do you really want that?

A more logical way would be to simple use different pools per bullet type, store the pools in a dictionary and use the prefab as a key (or what ever your code uses to mark different bullet types). You could even write a generic “wrapper” class if you have multiple cases where you need this logic.
Your spawn code can then specific which bullet type you want, get the correct pool and spawn the correct bullet from the type specific pool.

The Pooling API is a decent start but you still have to write some custom “wrapper” classes like this to avoid boilerplate code

1 Like

Thanks, that’s precisely how I implemented my home-grown object pooling as (I even did a video on it).

I guess I was expecting the new built-in pooling to do that piece as well.