Learning Unity — The Singleton Design Pattern

Photo by Laker from Pexels

Why Singleton?

In software, it’s important for there to be only one instance of certain things. For instance, if there were more than one instance of the file system, matters could very easily get confused and huge problems could result.

How Singleton?

Now for the real question: how do we do this? Fortunately, as I wrote earlier, this is very simple.

A default newly created script.
Our completed singleton script.

What next?

What we have accomplished here is implement the singleton pattern on this script, but at this point the script doesn’t really do anything. What comes next is giving the script purpose.

Conclusion

Learning design patterns such as the singleton can really help us with keeping up best practices and getting ahead of potential issues with our projects. The singleton is an excellent starting point, and I highly recommend looking into additional design patterns.

--

--

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