dyrda.
page science technology design games art page

Singleton MonoBehaviour for Unity

This package for Unity provides an implementation of the Singleton pattern for MonoBehaviour instances. The package introduces the SingletonMonoBehaviour class. With this class, we can create concrete MonoBehaviour components that can be added to game objects in the scene and behave in the same way as classic MonoBehaviour components–just as a singleton.

If you want to read more about the singleton pattern, check out Game Programming Patterns - Singleton by Robert Nystrom.

Quick Start: You may find yourself in the following situation: you have a class that currently inherits from MonoBehaviour and you want it to be a Singleton. Don't worry, it's super easy to use the package. Just follow the Quick Start guide from the project readme.

Features: The class implements the most common features described for MonoBehaviour Singletons. The feature list includes Event Functions, Persistence, "Exactly one Singleton, not more", "Exactly one Singleton, not less", Inactive Singletons, Thread Safety, Loading on Demand, Performance Optimizations, and Logging. You can find a complete list with all features and more details in the project readme.

The project is free and open source: You can find the source code and further details in the project repository on GitHub. If you are interested in updates, get in touch and support the project.

A screenshot of the game "Marble Maze".
Signature
navigation