Skip to content

Object Pool

Instantiating GameObjects at runtime can be expensive. Spawning many objects at once can cause frame-rate hitches - both during instantiation and later during garbage collection.

A common strategy to avoid this is object pooling:

Pre-instantiate a pool of reusable GameObjects. You pay the cost once (for example, at the start of a level), and then reuse the objects efficiently throughout gameplay.

Quick Start

Debug pools while playing using the Debug > Object Pools window

Actions

Create

Create and configure an object pool up front.

Spawn Object At Position

Spawn one pooled object at a world position.

Spawn Object At Transform

Spawn one pooled object at a transform.

Spawn Objects Radial 2D

Spawn multiple pooled objects in a 2D radial spread.

Spawn Objects With Offsets

Spawn multiple pooled objects with per-item offsets.

Release Object

Return a spawned object back to its pool.

Clear

Clear pooled instances from one pool.

Clear All

Clear pooled instances from all pools.

PooledObject Component

When an object is added to a pool, a PooledObject component is automatically added. This component stores a reference to the object pool so the object can release itself when finished.

You can also add the PooledObject component manually to prefabs that you know will be used with pooling.

Resetting Pooled Objects

Pooled objects are not constructed fresh - they keep whatever state they had last time. Make sure you explicitly reset them when they are spawned and cleaned up when they are despawned.

Practical tips

  • If you rely on initial variable values, enable Reset Variables in the FSM Inspector.
  • Use the Start State to reset the state of your object when set active (spawned from the pool).
  • If your FSM changes children (active state, transforms, materials, animations, etc.), restore them when the FSM starts again.
  • Use the OnDisable system event to do any needed cleanup when disabled (returned to the pool).