Object Pool Implementation


Reason for the change:

As a team we agreed that our game would have many spawning and destroying of objects in the world either by bullet destruction, the different types of currency drops and all the different types of enemies.  We wanted to tackle this early on to reduce potential cpu usage for our game so we agreed to implement an object pool to the world.

How the Object Pool Works:

The Object Pool does a simple thing, spawn all the actors and sort them into arrays that can be pulled from at any time from anywhere.  While in the pool all actors will not be rendered and will not have collision or any other components.  Essentially the actor has been turned off.  To use an actor you can request one and designate its transform location in the world.  But every actor such as the spawner that uses the pool doesn't know of the pool.   Though every actor does have access to the game instance.  I have implemented a new manager that the game instance holds called the Object Manager.  This manager is what requests the desired actor to return.  Best way I can describe this as when an actor is needed to spawn the customer can request if one is available.  The manager will check the pool.  If a actor exists then it is returned to the customer with its components enabled and the customer can do what ever is needed from there.  Once the object has done what it needed (destroyed) it is returned to the pool through the manager with all the its components disabled.  

Current Actors using the Pool:

  • Enemy 1: TwoLegged Damaged
  • Currency: Points
  • PowerUps: DoublePts
  • CurrencyContainer
  • Bullets: Rifle
  • Bullets: Pistol


(in this image the object pool will be visualized when it normally isn't)


Other Outcomes to the Object Pool:

A cool side affect to setting up the pool is that it also gives great control of how many objects of a certain type can exist in the world for example the double points powerup.  Only one exists that so if another tries to spawn it is unable too cause the pool states that there are none in stock till the powerup has been picked up or its destruction timer ends and is returned to the pool.  This also applies to the enemies making it easier to control how many enemies can be out at a time with keeping a consistent ratio of different enemies once we set up more enemies.

Get Project Meltdown

Leave a comment

Log in with itch.io to leave a comment.