Essential Systems / Object Pooling
Object Pooling
Enjoying Essential Systems?Leave a reviewLearn to use the included object pooling.
Setup
- Create a
Resourcesfolder anywhere in the project. - Inside it, create a
Poolasset via Create → Essentials → Pooling → Pool. - Select the asset, add entries under Objects, and assign your poolable prefab and an initial pool amount.
There must be exactly one
Poolasset in the project. Either remove the one at Pooling → Demo → Resources → Pool or reuse it.
Making an object poolable
Replace MonoBehaviour with APoolable:
// before
public class TestClass : MonoBehaviour { }
// after
public class TestClass : APoolable { }
Replace Awake() and Start() with OnAwake() and OnStart().
If the object has sibling or child MonoBehaviour components, they must implement IPoolableFamily:
public class TestSiblingClass : MonoBehaviour, IPoolableFamily { }
Initializing the pool
The pool must be initialized before use. The recommended approach initializes it once before any scene loads:
public class InitializePool
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void Initialize()
{
Pool.Init();
}
}
Alternatively, call Pool.Init() in an Awake() method, though this risks initializing multiple times if the scene reloads.
Spawning and destroying
Replace Instantiate() with Pool.Acquire():
TestClass copy = (TestClass)Pool.Acquire(obj, transform.position, Quaternion.identity);
Replace Destroy() with Dispose():
copy.Dispose();
Last updated

