Pool

Implementation of Unity's ObjectPool. (https://docs.unity3d.com/ScriptReference/Pool.ObjectPool_1.html)

Includes both standard class version and MonoBehaviour version.

GameObjectPool

Standart class version.

Contructor

Name
Type
Description

defaultCapacity

int

The default number of objects to allocate in the pool at initialization.

maxSize

int

The maximum size of the pool.

prewarm

bool

A boolean indicating whether to preallocate the default capacity of objects in the pool (default is true).

collectionCheck

bool

A boolean indicating whether to perform collection checks (default is true).

Usage

// Create
GameObjectPool projectilePool = new GameObjectPool(_projectilePrefab, 2, 4);

// Use
GameObject projectile = _projectilePool.Pool.Get();

// Dispose
_projectilePool.Pool.Dispose();

GameObjectPoolList

MonoBehaviour, list of pools. Create and destroy multiple pools.

// Get
GameObjectPoolList poolList = GetComponent<GameObjectPoolList>();

// Create pool and get it's id
Guid id = _poolList.CreateNewPool(_vfxPrefab, defaultCapacity, maxSize);

// Get an object from the pool with id
GameObject vfx = _poolList.GetPool(_id).Pool.Get();

// Dispose all pools in the list
poolList.Dispose();

MonoGameObjectPool

MonoBehaviour version of GameObjectPool. Auto prewarm on Awake.

Last updated