unity-singleton-pattern
Implementation of global manager access with strict lifecycle control. Supports Standard, Persistent, and Regulator variations.
How do I install this agent skill?
npx skills add https://github.com/muharremtozan/unity-agent-skills --skill unity-singleton-patternIs this agent skill safe to install?
- Gen Agent Trust Hubpass
The skill provides standard C# code templates for Unity design patterns, specifically focusing on Singleton lifecycle management. No security vulnerabilities or malicious behaviors were detected.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
What does this agent skill do?
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
- Singleton<T>: Standard management. Destroys new duplicates to keep the original.
- PersistentSingleton<T>: Extends Singleton with Don't Destroy On Load (DDOL) for cross-scene state.
- RegulatorSingleton<T>: Advanced inverse logic. Destroys OLD instances and keeps the NEWEST (useful for hot-swapping).
- StaticInstance<T>: 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>.
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/muharremtozan/unity-agent-skills/unity-singleton-pattern">View unity-singleton-pattern on skillZs</a>