Unity 3D – Object Pools and why you should be using them, speed up!

object-pool

Are you shooting bullets or creating any other objects in your game at runtime using functions like Instantiate? If the answer is yes then you probably haven’t heard of object pools.

Creating and destroying objects is expensive in execution time and inefficient, it is much better to say have 10 invisible bullet objects in your scene and then simply use these when you need to, that is:

  • Move the object to your gun
  • Make the object visible
  • Animate it (move per frame in a bullety style!)
  • When you’re finished with the bullet, say it hit something, just hide it again.
  • Repeat

So no creating or destroying objects, no wasted time, you are simply re-using existing objects.

There are lots of guides to help you create your own “object pool” on the internet already, there is also free source code as well as plenty of paid assets on the asset store. Here is list of some I found:

If you know of better examples, leave a comment and I’ll add them to the list.

2 thoughts on “Unity 3D – Object Pools and why you should be using them, speed up!

  1. Pingback: Jay
  2. Pingback: jesse

Comments are closed.