Singleton Pattern
Singleton is a Programming Design Pattern:
In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system wikipedia
An implementation of the singleton pattern must:
ensure that only one instance of the singleton class ever exists
provide global access to that instance
Singleton in Unity:
In Unity, Singletons are often used for management of aspects a game such as: state-manager, data-manager, audio-manager, etc.
In Unity, the Singleton Pattern should ensure:
only one instance of the object exists
in each scene, it's necessary to destroy any instances that are created as duplicates
A global, static variable should be initialized that creates an object-reference to the singleton object.
Code to create a Singleton should be located in Awake( );
StateManager Singleton
Last updated