Spawning an Army of Units
RTS games have a gameplay mechanic that allows you to spawn units and create large armies to battle enemies. But having so many objects in the same scene that can be easily created and destroyed requires good memory and CPU management, to avoid problems such as frame rate drops due to CPU spikes, out-of-memory issues, and memory leak issues due to inefficient memory usage. There is one programming pattern that works well in this scenario, which is called Object Pooling, and we are going to learn how to implement and use it to spawn our units.
In this chapter, we will create the configuration files for our units using the
ScriptableObject class from Unity, which will have all the attributes we need to use a unit in our game. We are also going to see how to update the UI using a decoupled solution by learning how to implement and use the Message Queue pattern, which provides a great way for scripts or systems to communicate with each other without creating...