C# Design Patterns in Unity3D : Singleton

C# Design Patterns in Unity3D : Singleton

In software development, design patterns help us to solve some common problems in our projects. It’s better if you use this patterns as a guide at the start of your project. If you stuck anywhere on your project, it’s time to find out a pattern that you need. You may not meet any problem in small-sized project but you exactly need a pattern in complex projects. Singleton Design Pattern is one of the most important pattern in software development.



Simple and useful. Singleton pattern is easy to implement and it provides handy solutions for your project. You create an instance and call its functions from another scripts. Static classes are used in this pattern. As you know, static classes cannot be changed by another script. So, it cannot be duplicated which means its safe to use. On the other hand, static classes cannot use MonoBehaviour, cannot use parameters and cannot be used for GUI.

Now, you can call Instance() function from another script.

Screen Shot 2015-06-09 at 15.59.23

You don’t need to write Singleton class in every script you use. You create a unique instance and use it everywhere.




©Coffee Break Codes – C# Design Patterns in Unity3D : Singleton

Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “C# Design Patterns in Unity3D : Singleton

  • Faizan

    Hy all,
    I am interested in a project named ‘3D password Authentication’. In it there will be a 3d virtual environment and there will be objects in it and the user will interact with those objects for authentication process.
    So, my question is if it is possible to create a virtual environment in unity and then integrate that environment with java / C# and also with the Sql for database and all this will then be converted to a desktop application.
    Please reply. Thanks in advance.