![]() |
VOOZH | about |
Object pooling is a performance optimization technique. Instead of destroying an object, you deactivate it and add it back to a pool. When needed again, you reuse it instead of creating a new one.
When you instantiate and destroy objects frequently, Unity keeps allocating and freeing memory. This causes lag spikes.
Every time you destroy an object, Unity's garbage collector has to clean it up later, causing frame drops.
Create a pool of objects at start. Reuse them instead of destroying.
Here's how to shoot using the object pool.
Create one pool that works for any type of object.
Usage:
| Feature | Without Pooling | With Pooling |
|---|---|---|
| Object Handling | Uses Instantiate() and Destroy() repeatedly | Reuses objects (activate/deactivate) |
| Performance Impact | Causes garbage collection → lag spikes | Avoids garbage collection overhead |
| Speed | Slower | Much faster |
| Implementation | Simple to implement | Requires extra setup/code |