Updating the UI using the Message Queue pattern
The Message Queue pattern, also known as the Event Queue pattern, consists of a list of messages that are sent to all other scripts that are listening for a specific message. This is a powerful pattern that helps to decouple different scripts since you can just send a message with an update and the listener will receive and process it, without having shared variables across the whole project.
It also has good performance since the listeners are not checking for new messages on every loop. When a message is received, the message queue will trigger the listeners that are assigned to the type of message received.
We are going to implement the Message Queue pattern and use it to update the game UI and spawn new units. The idea is that when a new unit is required to be added to the game, a message will be sent by the script requesting it and received by the script that will then get a unit from the Object Pool. Both patterns work together...