Unity Object Pooling: How to Use Object Pool in Your Game
When working on a Unity game, you may need to create and destroy the same type of object again and again. Bullets, enemies, coins, explosions, and particle effects are common examples.
At first, using Instantiate() and Destroy() seems perfectly fine. But when hundreds of objects are created and destroyed during gameplay, it can affect performance.
This is where Unity Object Pooling can help.
In one of my Unity projects, I needed to reuse objects many times during gameplay. Instead of creating a new object every time, I created a pool of objects and reused them whenever needed.
In this tutorial, I'll show you how to use object pool in Unity with a simple bullet example.
What Is Unity Object Pooling?
Unity Object Pooling is a technique where we create objects once and reuse them instead of constantly creating and destroying them.
For example, without pooling, a shooting game may work like this:
Shoot
↓
Instantiate Bullet
↓
Bullet Hits Enemy
↓
Destroy Bullet
This happens again every time the player shoots.
With object pooling, the process becomes:
Create Bullets
↓
Store Them in Pool
↓
Get Bullet
↓
Use Bullet
↓
Return Bullet to Pool
↓
Reuse Bullet
The main idea is simple: reuse objects instead of creating new ones every time.
Why Use Object Pooling in Unity?
Object pooling is useful when your game creates and removes the same objects frequently.
Some common examples are:
- Bullets
- Enemies
- Coins
- Explosions
- Particle effects
- Projectiles
- Damage numbers
It can reduce the amount of repeated Instantiate() and Destroy() calls and help avoid unnecessary performance overhead, especially when many objects are involved.
How to Use Object Pool in Unity
Let's create a simple object pool for bullets.
Step 1: Create a Bullet Prefab
First, create your bullet GameObject and add the components you need.
For example:
Bullet
├── Sprite Renderer
├── Collider2D
└── Rigidbody2D
Once the bullet is ready, drag it from the Hierarchy into your Project folder to create a prefab.
We will use this prefab to create our pool.
Step 2: Create the Object Pool Script
Create a C# script called ObjectPool.
Add the following code:
using System.Collections.Generic;
using UnityEngine;
public class ObjectPool : MonoBehaviour
{
public GameObject objectPrefab;
public int poolSize = 20;
private Queue<GameObject> objectPool = new Queue<GameObject>();
void Start()
{
for (int i = 0; i < poolSize; i++)
{
GameObject obj = Instantiate(objectPrefab);
obj.SetActive(false);
objectPool.Enqueue(obj);
}
}
public GameObject GetObject()
{
if (objectPool.Count > 0)
{
GameObject obj = objectPool.Dequeue();
obj.SetActive(true);
return obj;
}
return null;
}
public void ReturnObject(GameObject obj)
{
obj.SetActive(false);
objectPool.Enqueue(obj);
}
}
Don't worry if the code looks a little new. The idea is quite simple.
We create a number of objects when the game starts and keep them inside a Queue.
For example:
public int poolSize = 20;
creates a pool with 20 objects.
These objects are initially disabled:
obj.SetActive(false);
They are now ready to be reused.
Step 3: Create the Pool in Unity
Create an empty GameObject in your scene and rename it:
BulletPool
Attach the ObjectPool script to it.
In the Inspector, you will see:
Object Prefab
Pool Size
Drag your Bullet prefab into Object Prefab and set the pool size to something like 20.
When you press Play, Unity will create the bullets and keep them disabled.
Step 4: Get an Object From the Pool
Now we can use the pool when the player shoots.
For example:
public ObjectPool bulletPool;
void Shoot()
{
GameObject bullet = bulletPool.GetObject();
if (bullet != null)
{
bullet.transform.position = transform.position;
}
}
Instead of creating a new bullet with:
Instantiate(bulletPrefab);
we get an existing bullet from the pool:
bulletPool.GetObject();
The bullet is then activated and can be used normally.
Step 5: Return the Object to the Pool
When the bullet hits an enemy or leaves the screen, we don't destroy it.
Instead, we return it to the pool:
bulletPool.ReturnObject(gameObject);
The object is disabled and placed back into the pool.
Later, when another bullet is needed, the same GameObject can be reused.
This is the main benefit of Unity Object Pooling.
Don't Forget to Reset the Object
There is one important thing to remember.
A reused object may still have its previous state.
For example, a bullet may still have its old:
- Position
- Rotation
- Rigidbody velocity
- Animation state
- Health or other values
So make sure you reset anything that needs to be reset when the object is reused.
For a Rigidbody2D bullet, for example:
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.linearVelocity = Vector2.zero;
rb.angularVelocity = 0f;
Then set its new position and direction.
Object Pooling Design Pattern
The Object Pooling Design Pattern is not specific to Unity. It is a general programming pattern used to manage reusable objects.
The basic flow is:
Create Object
↓
Store in Pool
↓
Get Object
↓
Use Object
↓
Return Object
↓
Reuse
This approach keeps object creation in one place and allows different parts of the game to request objects when they need them.
Unity also provides a built-in pooling API through UnityEngine.Pool, which can be useful when you want a more advanced and reusable pooling system.
When Should You Use Object Pooling?
You don't need to use pooling for every GameObject.
It makes the most sense when an object is:
- Created frequently
- Destroyed frequently
- Reused many times
- Needed in large numbers
For example, a bullet in a shooting game is a great candidate for pooling.
On the other hand, objects such as a main menu, player character, or settings panel usually don't need an object pool because they are not repeatedly created and destroyed.
Final Thoughts
Unity Object Pooling is a simple but useful technique for games that frequently create and destroy objects.
Instead of doing this:
Instantiate → Use → Destroy
we can do:
Get From Pool → Use → Return To Pool
When I used this approach in my game, it made more sense to create the objects once and reuse them rather than repeatedly creating new ones.
If you're working on a shooting game, endless runner, survival game, or any project with lots of repeated objects, learning how to use object pool can be very useful.
Start with a simple pool like the one above. Once you understand the concept, you can move to Unity's built-in pooling system and create a more flexible solution.
Frequently Asked Questions
1. What is Unity Object Pooling?
Unity Object Pooling is a technique that reuses GameObjects instead of repeatedly creating and destroying them.
2. How do I use object pool in Unity?
Create a group of objects in advance, get an object when you need it, activate it, and return it to the pool when you are finished with it.
3. What is the Object Pooling Design Pattern?
The Object Pooling Design Pattern is a programming pattern that stores reusable objects so they can be used again instead of being recreated.
4. Does object pooling improve Unity performance?
It can improve performance when many short-lived objects are repeatedly created and destroyed. The actual benefit depends on your game's workload.
5. Which objects are good for object pooling?
Bullets, enemies, projectiles, coins, explosions, particle effects, and damage numbers are common examples.











