Singletons: A Common Programming Pattern (Game Dev Day 65)

Jack Leavey
Jan 21, 2022

As mentioned briefly in my previous article, singletons are a pattern commonly used in programming both in and outside of Unity.

A Singleton is a class with only allows a single instance of itself to be created and accessed. These allow for you to call and store variables from various other sources and reference them from the script utilizing the Singleton pattern.

Using a Singleton to access the “HasCard” variable.

Singletons has many uses, but the utilization in my case is for my manager class objects (Game Manager, Audio Manager) due to the need to constantly access other scripts to get information. Instead of using GetComponent a dozen times, I can utilize this Singleton to store the information needed until it needs to be called.

--

--

Jack Leavey

I am a software engineer with years of experience branching into game development, specifically in Unity. Follow along for guides on creating game mechanics!