mcpField
U
unity-singleton-pattern

unity-singleton-pattern

github.com/muharremtozanDevelopment1751 installsUpdated 22w ago
Repository

About unity-singleton-pattern

A set of Unity Singleton variants for developers managing global systems such as game, UI, and input managers. It includes persistent and newest-instance variants alongside standard duplicate prevention.

Key features

  1. 01Standard duplicate prevention
  2. 02Cross-scene persistence
  3. 03Newest-instance regulation
  4. 04Static global access

Use cases

  1. 01Managing a global UI manager
  2. 02Keeping inventory state across scenes
  3. 03Replacing an existing music system

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/muharremtozan/unity-agent-skills --skill unity-singleton-pattern

After installing, type/unity-singleton-patternin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

assets/code/
SingletonBase.cs.txt
SingletonExample.cs.txt
SingletonRegulator.cs.txt

Details

From the project README

Unity Singleton Pattern

A robust suite of Singleton variations for global systems. Adheres to the Ohm-Yura project rule: "Use Singletons ONLY for global systems (GameManager, UIManager, InputManager)."

Core Features

  1. Singleton: Standard management. Destroys new duplicates to keep the original.
  2. PersistentSingleton: Extends Singleton with Don't Destroy On Load (DDOL) for cross-scene state.
  3. RegulatorSingleton: Advanced inverse logic. Destroys OLD instances and keeps the NEWEST (useful for hot-swapping).
  4. StaticInstance: Lightweight global access without duplication enforcement.

Core Files (Max 3)

  • SingletonBase.cs.txt: Generic base classes for classic and persistent variants.
  • SingletonRegulator.cs.txt: Logic for the time-stamped regulator variant.
  • SingletonExample.cs.txt: Concrete examples for Game and UI managers.

Usage

1. Standard Manager
public class UIManager : Singleton<UIManager> { }
// Use via: UIManager.Instance.Show();
2. Persistent Manager
public class InventoryManager : PersistentSingleton<InventoryManager> { }
// Survives scene changes.
3. Regulator (System Swap)
public class MusicSystem : RegulatorSingleton<MusicSystem> { }
// Spawning a new one will automatically kill the old one.

Key Principle

Always use the most restrictive version. If it doesn't need to persist cross-scene, use Singleton<T>. If you just need a reference but don't mind duplicates, use StaticInstance<T>.

Comments

Markdown supported