Essential Systems / Object Pooling

Object Pooling

Enjoying Essential Systems?Leave a review

Learn to use the included object pooling.

Setup

  1. Create a Resources folder anywhere in the project.
  2. Inside it, create a Pool asset via Create → Essentials → Pooling → Pool.
  3. Select the asset, add entries under Objects, and assign your poolable prefab and an initial pool amount.

There must be exactly one Pool asset 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