A minimal and reusable set of MonoBehaviour singleton base classes for Unity.
Just inherit and use T.Instance — no boilerplate, no hassle.
| Class | Auto-create if missing | Persistent (DDOL) | Notes |
|---|---|---|---|
Singleton<T> |
✅ Yes | ❌ No | Auto-instantiated when accessed |
PersistentSingleton<T> |
✅ Yes | ✅ Yes | Auto-instantiated + marked as DontDestroyOnLoad |
SingletonBehaviour<T> |
❌ No | ❌ No | Must be in the scene manually |
PersistentSingletonBehaviour<T> |
❌ No | ✅ Yes | Must be in the scene manually, persistent after Awake() |
// GameManager.cs
public class GameManager : Singleton<GameManager>
{
public void Initialize()
{
Debug.Log("GameManager ready!");
}
}// Anywhere else
GameManager.Instance.Initialize();- If using
Singleton<T>orPersistentSingleton<T>, the GameObject is created automatically. - If using
SingletonBehaviour<T>orPersistentSingletonBehaviour<T>, ensure the script is placed in the scene.
Add this package to Unity via Git URL:
- Open Unity, then select Package Manager
- Click the + button and select Add package from Git URL
- Enter :
https://github.com/BcoffeeDev/game-core-pattern-singleton.git
Or edit manifest.json:
"dependencies": {
"com.bcoffee-dev.patterns.singleton": "https://github.com/BcoffeeDev/game-core-pattern-singleton.git"
}Found a bug or have a feature suggestion?
Feel free to open an issue or submit a pull request!
All contributions are welcome and appreciated.
MIT © 2025 BcoffeeDev