Table of Contents

Interface IPool<T>

Namespace
Gamelogic.Extensions
Assembly
Gamelogic.Extensions.dll

Represents a pool of objects, with the idea to reuse objects instead of creating and destroying them.

[Version(3, 2, 0)]
public interface IPool<T>

Type Parameters

T

The type of the objects to pool.

Extension Methods

Remarks

Unity introduced its own pool objects in Unity 2020. The built-in pool is similar to the one provided here, but this interface gives a bit more control over managing objects.

Here are some differences:

  • Unity pools do not allow you to specify the creation or destruction of pool objects.
  • Unity pools do not allow you to specify activation and deactivation actions.
  • Unity pools do not offer ways to manage the capacity of the pool explicitly.

What pool should I use?

When should I use a pool?

  • When allocations of objects are expensive, such as creating game objects in the scene.
  • When you do a lot of allocations and de-allocations of the same type of object, such as in custom a particle system

We have several examples of how you can use our pools to build more sophisticated pools: Custom Pools.

Properties

ActiveCount

The number of objects that are currently active.

Capacity

The total number of objects in the pool (active and inactive), the maximum number of objects that can be returned by Get().

HasAvailableObject

Returns whether there is an inactive object available to get.

Methods

DecreaseCapacity(int, bool)

Decreases the capacity of the pool.

Get()

Gets a new object from the pool.

IncreaseCapacity(int)

Increases the capacity of the pool.

Release(T)

Releases the specified object back to the pool.

ReleaseAll()

Releases all objects in the pool.