A Single(ton) Manager

After the creation of the managers, it’s time to pass the necessary information to objects that need them. After all, managers should be relaying important information to its subordinates. However, how do we do that to ensure information relayed are current and accurate?

The Good Way

In Unity, there are several ways to ensure the information stays current and accurate. One of these ways is to reference it in other scripts via a variable.

Game Manager script
UI Manager getting a reference to the Game Manager

In this example, the UI Manager is getting a reference to the Game Manager via a variable created in the UI Manager script.

Even though this method is good, as there’s a reference to the Game Manager, it requires other scripts to have variables ready to accept the Game Manager reference. As a result, it might become cumbersome when the game gets bigger.

The Better Way

Another way to relay information to other scripts is via Singleton pattern. Similar to the method above, using Singleton pattern also requires scripts to reference it in order to relay information from the Game Manager.

However, unlike the method above, it doesn’t require a reference variable to store the data; you can call the class directly due to only one instance of the Game Manager being created and it being stored in the memory.

Getting Started

Singleton pattern looks similar like any other scripts in Unity. However, the difference between any other scripts in Unity and a script that’s in the Singleton pattern is the inclusion of properties.

In this example, the properties are set in static so only one instance is created and can be called or modified.

Furthermore, in the public property of the Game Manager script, there’s a check to ensure the instance of the Game Manager class was created; if it does, then it will return the instance.

Lastly, by setting the instance to itself in the Awake() method, we are ensuring the instance is created once the Game Manager wakes up.

Once the properties are created, the rest of the script looks the same as any other scripts in Unity.

Referencing the Singleton

After creating the Singleton script, now it’s time to reference it. Like before, unlike the previous method, referencing a singleton method is simple:


There are no need to reference it externally (assigning the game object that holds the Game Manager script) or internally (via Find By Tag)

For example, in order for me to determine if the player has the keycard, I would reference it like this





Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Network statistics tool Darkstat

Programming on Hard Mode: Markov chains for creating game titles

A Look at Pluto’s Technology Stack

One ring (zero) to rule them all.

Controller, Service, and Repository Layer Unit Testing using JUnit and Mockito

Looking for the Best SQL-On-File Tool

New Features in Java

Salesforce Implementation Services: 6 Mistakes that occur during Salesforce CPQ Implementation

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Josh Vang

Josh Vang

More from Medium

Five Mistakes When Doing a Quarterly Review

What is primacy effect psychology definition ?

Create a simple timeline in Nativescript-vue