GameObjectPooler is now available on Unity Asset Store. It’s based on an entirely static helper class with easily accessible extension methods. This means you can simply call
instance.Recycle(). And basically that’s it! No tedious manual setup required! Of course the system provides more optional features, if you need them.
If you are not familiar with extension methods, check out my article on the subject here.
Object pooling is a pattern where you avoid creating new objects when you can reuse the old. In practice, it’s much like recycling in the real life. Processing the used objects into reusable objects requires an infrastructure to make the processing possible. And when the system is setup, it helps to save the valuable resources when used in the right manner.
There are decent articles on the subject. See for example the official Unity tutorial, Mark Placzek’s post on raywnenderlich.com, and the tutorial on catlikecoding.com. I’ve studied these tutorials, but my solution is not directly based on them.
Personally, I dislike configuring trivial things in editor, because it takes time and because they are easily broken. What I aimed for instead, is a solution where you could simply replace your
Destroy(instance) calls with corresponding methods. So that’s what I did.
- Can easily handle thousands of objects
- Fully automatic, no tedious manual setup required
- Simple to use with extension methods: just replace
- Prefabrication and releasing objects by demand
- Automatic parenting
- Callbacks and C# events for resetting the objects (Unity callbacks, OnEnable() and OnDisable() can be used as well)
- Garbage-free events on object creation, destruction, activation, and inactivation
- Direct and unrestricted access to the object pools for best performance and control (no hand-holding!)