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?
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.
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.
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.