Unity Object Pool Asset
Overview
A high-performance Object Pool system specifically designed for use with Unity. It utilizes a sparse set, allowing for fast operations on the pooled data, even with very large pool sizes.
The main objectives for this asset was for an efficient way to pre-allocate + store high quantities of objects and easily take unused/disabled objects from the pool for (re)use, rather than (re)instantiating and destroying the same object type over and over, which causes additional GC allocations + CPU time (due to C#'s GC and Unity's C# <-> C++ interop).
The object pool uses a sparse set as an efficient data structure for determining what objects are enabled or disabled. It's designed to be adaptable to various needs via events and custom callbacks. It provides an extended class specifically for gameobjects, with optional syncing for the pool's node and gameobject's enabled state.
Asset Download: Latest Release
Examples + Source Code: eilume/unity-object-pool
Demo
"Bullet Hell Demo" showcasing the frame-time difference from using an object pool, even with extremely simple gameobjects. The difference is actually greater since rendering takes around 3ms (regardless of pooling)
Technical Sheet
Tools that I used whilst working on this project:
- IDE:
- Game Engine:
Helpful Resources
- Sparse Set - Blog post about sparse sets