Object pooling for every device

Desktop, Laptop, Tablet, Mobile, Console

What is Object Pooling?

A simple and effective optimisation, for game programming and other high performance situations. Use Pure Pool to ensure a smooth and responsive game.

Pure Pool is the only fully-serialisable object pool for Unity. Pools, all of their settings, and all of their statistics, are all serialisable. Make the most of Unity's ability to hot reload code (also called live recompilation) for rapid prototyping and iterative development, without losing your pools in the process.

Features

High-performance

Avoid the overheads of garbage collection. Lightning fast instantiation and destruction due to object pooling.

Statistics

Monitor your pools in real-time. View in the inspector or access through code, and ensure your pools are performing optimally. Recommended pool size helps you avoid generating garbage.

Recycling

Re-use your Unity game objects and regular C# objects. Simply reset their values when you take them from the pool, and never instantiate again.

Optimised Code

Powerful C# API and performance-tested code. Create, modify, and delete pools at runtime. Acquire and release hundreds of objects per frame.

Source Code

Fully-commented and documented source code. Visual Studio 2017 solution included. Written to use the latest C# 7 syntax. Conditional compilation allows disabling of unwanted features.

Customisable

Change pool settings in the inspector or from code. Initial size, maximum size, notification modes, events - and much more.

Custom Inspector

Custom inspectors give you great power at your fingertips. Drag and drop to create pools, organise them within nested containers, and search using regular expressions. Undo support and prefab overrides, as expected.

Networking Support

Integration libraries and scripts for both Unity 5+ Networking (UNet) and Photon Unity Networking (PUN) help make object pooling simple, even for networked games.

Code Examples

Create a Pool


// Create the pool for the asteroids.
this.PoolManager.CreatePool(new GameObjectPoolSettings {
	Source = this.Asteroid,
	InitialSize = 85,
	MaximumSize = 100,
	InitialiseOnStart = true,
	LogMessages = LogLevel.Information,
	DontDestroyOnLoad = false
});

Creating a new pool at runtime is easy. The provided GameObjectPoolSettings class has sensible default values and can be changed as required.

Create a Serialisable Custom Pool


// Subclass SerialisableObjectPool to create your own serialisable pool for any type.
[Serializable]
public class MyCustomClassObjectPool : SerialisableObjectPool<MyCustomClass> { }

[SerializeField, HideInInspector]
private MyCustomClassObjectPool pool;

// Set up the pool in your Awake or Start method.
this.pool = new MyCustomClassObjectPool {
	InitialSize = 10,
	MaximumSize = 100,
	InstantiateWhenEmpty = false
};

// Call initialise when your pool is set up. It's now ready to use!
this.pool.Initialise();

Create a serialisable pool for any type. The pool will survive assembly reloads and allows for quick prototyping.

Object.Instantiate Replacement


// Acquire (pool-based replacement for Instantiate) an asteroid.
this.PoolManager.Acquire(this.Asteroid, position, Random.rotation, this.transform);

// Instead of the original:
Object.Instantiate(this.Asteroid, position, Random.rotation, this.transform);

Swapping out Instantiate for the pool-based Acquire is as easy as using Find-and-Replace. Access the Manager statically through PoolManager.Instance.

Object.Destroy Replacement


// Release (pool-based replacement for Destroy) the asteroid.
this.PoolManager.Release(this.gameObject);

// Instead of the original:
Object.Destroy(this.gameObject);

As with Instantiate, replacing Destroy is as simple as using the Release method on the Manager.

For further code samples and tutorials, see the online documentation for Pure Pool and the API reference.