Object Pooling

VariaBULLET2D offers a simple yet robust object pooling system which reuses – rather than destroys – Shot gameobjects that are no longer needed in the scene (such as after hitting an enemy or extending past the visible area on the screen). Reuse in this way can have a profound impact on performance, especially in cases where hundreds or even thousands of concurrent bullets appear on the screen.


It’s extremely easy to make use of VariaBULLET2D’s built-in object pooling system. Since each object pool is controlled at the emitter level, simply go to each emitter’s attached firing script and [A] select Pooling Enabled.

Almost all existing bullet types can make use of the pooling system and you won’t have to think about it beyond setting this one toggle (Lasers and a few complex shots types in particular do not use pooling and ignore the emitter’s pooling setting).

By default, the pool of shots grows only when they’ve already been fired and are no longer needed in the scene. However, by [B] enabling Auto Pool you can have the system decide to start with a pool of shots when the FireBullet script first becomes instantiated. This creates a pool of objects immediately in order to reap the benefits of pooling from the very start.

In many cases, however, this isn’t worthwhile. It won’t make much sense, for example, to spawn an enemy with a pool of bullets if the enemy is not likely to stay alive long enough to need all of those bullets. On the other hand, if the enemy is a boss and is expected to need hundreds of bullets before it’s destroyed, then it may be useful to Auto Pool when the enemy is first instantiated.

You can choose to override whatever amount of bullets the system creates when auto pooling with Auto Pool Override. The Auto Pool setting tends to estimate on the conservative side, so if you run tests and find that you will likely need more bullets pooled at start, then you can easily count how many bullets end up pooled over a period of time and [C] input that total amount manually for Auto Pool Override. The default value of 0 does not change the Auto Pool amount at all.

Note: in v1.03 a “Banking Enabled” pooling option was added at the emitter-level firing scripts. Banked shots are managed via the GlobalShotBank whereas Pooled shots are managed via the emitter that fired the shot. The main difference is banked shots are not destroyed when the shot’s emitter is destroyed, and remain persistent as the scene progresses. Both options can be used simultaneously. Note that shots that have sprite overrides set by their firing scripts cannot be globally banked. For more banking options, including pre-loading shots, bank limits, etc, see the GlobalShotBank prefab in System > Resources > ND_VariaBULLET > GlobalManager