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
- Use ObjectPool Spawn Object At Position instead of Instantiate to spawn an object from a pool.
- Use ObjectPool Release Object instead of Destroy to return the object to the pool.
Debug pools while playing using the Debug > Object Pools window
Actions
Create and configure an object pool up front.
Spawn one pooled object at a world position.
Spawn one pooled object at a transform.
Spawn multiple pooled objects in a 2D radial spread.
Spawn multiple pooled objects with per-item offsets.
Return a spawned object back to its pool.
Clear pooled instances from one pool.
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).