VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/singleton-pattern-in-unity/

⇱ Singleton Pattern In Unity - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Singleton Pattern In Unity

Last Updated : 4 May, 2026

A singleton is a class that allows only one instance of itself to exist. Any script can access it from anywhere without needing a reference.

  • Only one instance exists in the game
  • Accessible from any script using ClassName.Instance
  • Persists across scenes (optional)

Basic Singleton Implementation

This is the simplest singleton pattern.

Now any script can call GameManager.Instance.StartGame() without finding or dragging references.

Complete Singleton (No Duplicates)

This version prevents duplicate instances from being created.

If a second AudioManager tries to spawn, it destroys itself. The first one remains.

Using Singleton from Any Script

Once you have a singleton, any script can access it directly. This is the main benefit - no dragging references in Inspector.

No need to drag references. Just call ClassName.Instance.MethodName() from anywhere.

Singleton vs Static Class

SingletonStatic Class
Inherits from MonoBehaviourCannot inherit from MonoBehaviour
Can use Unity methods (Start, Update)No Unity lifecycle methods
Can be placed in the sceneCannot be placed in the scene
Supports DontDestroyOnLoadNo scene persistence

When to Use Singleton

  • Good for: GameManager, AudioManager, ScoreManager, UIManager, SaveSystem.
  • Not Good For: Player (if multiple players), Enemies, Bullets, Items.
Comment
Article Tags:
Article Tags:

Explore