September 07 2022

Is Object Pooling "Dead" (Again)?


Is object pooling “dead” (again)?

NO.

Context: here is the question I got from Performance Taskforce member ZombieBust3r in our members-only Discord channel. It is about an isaac-like game he is developing.

Object Pooling: so many objects, still worth it?


I'm now looking into the shooting [mechanics]. I usually would go for object pooling, although considering the amount of "tear objects" that can exist at once in the game I'm not sure having as many instances of a prefab (even if it usually is just a couple sprites with a rigidbody and a couple scripts) **is object pooling still worth using when the number of instantiated prefabs will be something like 200 max?** My idea for this is to instantiate a smaller amount since you start with base stats and depending on fire rate and other things maybe instantiate a few more if necessary during gameplay.

Here’s my take on this:

When instantiation and/or destroy is expensive (time, GC allocs), pooling is worth. Otherwise, don’t chase another shiny object.

Evaluate pooling when your scripts are expensive in functions like:

  • Awake, OnEnable, Start
  • OnDisable, OnDestroy

Plus, it is not only your code that affects this. Also sneaky Unity code. Animators and particle systems are expensive to wake up, for instance.

Solution: measure it. Spawn 200 objects and profile the cost of that. You don’t like the cost you see? Okay, so pool it.

And another thing you can do is to still pool 200 bullets… and then adjust the specific bullet variation before activating it, such as the specific sprite to display.

You can ask questions like this in our Taskforce Q&A’s. If you want to jump in, you still have a couple of days before I release the next Taskforce module:

https://www.PerformanceTaskforce.com/

Ruben (The GameDev Guru)

The Gamedev Guru Logo

Performance Labs SL
Paseo de la Castellana 194, Ground Floor B
28046 Madrid, Spain

This website is not sponsored by or affiliated with Facebook, Unity Technologies, Gamedev.net or Gamasutra.

The content you find here is based on my own opinions. Use this information at your own risk.
Some icons provided by Icons8