Managing Collections of Game Objects

Object Pooling

“Creating new objects slows down the game. Lets reuse existing objects instead!”

What Is Object Pooling For?

Using Unity’s Instantiate function can slow down your game if you constantly creating objects including bullets, pickups, enemies, and obstacles. An alternative to this is to have a ObjectPooler, a script that instantiates game objects up to a certain point and then reuses existing objects when the game requires more objects spawned. Additionally, instead of destroying game objects when we are done with them, we use SetActive(false). This allows the ObjectPooler to call SetActive(true) to reuse the game objects again.

Object Pooling Architecture: Scriptable Objects

../_images/scriptable_object_pooling_system_diagram.svg

Example

Click to download ScriptableObjectPoolingExample.unitypackage.

../_images/scriptable_object_pooling_system_example_diagram.svg

Runtime Sets

“Fire All Weapons! … Ok but what and where are the weapons?”

What Are Rutime Sets For?

There are scenarios in your game when you need to keep track of objects in the scene:

  • In a real time strategy game you may need access to a set for all your tanks, boats, or airplanes so that the player can select them with a single keystroke.

  • In a game where you fight hordes of enemies the you may need access to the set of enemies in the level and the set of powerups in the world.

  • In a game where you manages a store you may need access to a set of all products and a sub set of produce products.

You can use runtime sets to track these things and give you the information when your game needs it.

Runtime Set Architecture: Scriptable Objects

Note

For more information on Scriptable Object Runtime Sets, see Unite Austin 2017 - Game Architecture with Scriptable Objects

../_images/scriptable_object_runtime_set_diagram.svg

Example

Click to download ScriptableObjectRuntimeSetExample.unitypackage.

../_images/scriptable_object_runtime_set_example_diagram.svg