How to create a generic Pool Manager?

Hello community!

I’m working on something on the lines of Vampire Survivors, with a lot of bullets and enemies of different types that I’m trying to have in a pool manager.

For now having a specific pool manager for the projectiles, but when starting to work on the next, I was hoping that I could have a PoolManager that I could call a Get<PoolableObject> type of thing.

I come from Unreal where we could easily use the class as a Key of a Map (the class, not an instance). I was hoping to achieve something similar but I don’t find a way for that.

Is this something achievable? How would you go about it yourself if the requirements were to have a simplified but still generic PoolManager?

Thanks a lot :slight_smile:

Yeah, I put something together in half an hour using Unity‘s ObjectPool class. I‘ll post the code when I‘m back.

The idea is that I pass in a prefab reference and get that prefab‘s InstanceID. The ID is used as a key in the Dictionary with values a simple wrapper class around ObjectPool that maintains the references eg put each in a specific sub-object.

Aha! I was not aware of instance IDs (first project in unity ever :sweat_smile:)! I’ll take a look at that!

For a bullet hell game you may find it’s more performant to use particles for the bullets rather than gameObjects. Although I’m sure you could still benefit from pooling particle systems too.

For a bullet hell game you may find it’s more performant to use particles for the bullets rather than gameObjects. Although I’m sure you could still benefit from pooling particle systems too.

Awesome! I’m gonna do research on that :slight_smile:

Or you can use DOTS in this case if you dont mind to learn new tech :smiley:

Here’s the pooling code sample, divided into PrefabPool (public API, pools keyed by prefab), PrefabInstancePool (internal, pool instances of a given prefab), and AutoReleaseToPool which will put the object back in the pool automatically if SetActive(false) - which I don’t use anymore but it was convenient initially.