Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8955447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:33:35+00:00 2026-06-15T14:33:35+00:00

In Unity, whats a good way to create a singleton game manager that can

  • 0

In Unity, whats a good way to create a singleton game manager that can be accessed everywhere as a global class with static variables that will spit the same constant values to every class that pulls those values? And what would be the way to implement it in Unity? Do I have to attach it to a GameObject? Can it just be there in a folder without being in the scene visually?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:33:38+00:00Added an answer on June 15, 2026 at 2:33 pm

    Like always: it depends. I use singletons of both kinds, components attached to GameObject and standalone classes not derived from MonoBehaviour. IMO the overall question is how are instances bound to the lifcycle of scenes, game objects, … And not to forget sometimes it is more convenient to have a component especially referencing other MonoBehaviour objects is easier and safer.

    1. There are classes that just need to provide some values like for example a config class that needs to load settings from persistence layer when called. I design theese classes as simple singletons.
    2. On the other hand some objects need to know when a scene is started i.e. Start is called or have to perform actions in Update or other methods. Then I implement them as component and attach them to a game object that survives loading new scenes.

    I designed component based singletons (type 2) with two parts: a persistent GameObject called Main, which holds all components and a flat singleton (type 1) called MainComponentManager for managing it. Some demo code:

    public class MainComponentManger {
        private static MainComponentManger instance;
        public static void CreateInstance () {
            if (instance == null) {
                instance = new MainComponentManger ();
                GameObject go = GameObject.Find ("Main");
                if (go == null) {
                    go = new GameObject ("Main");
                    instance.main = go;
                    // important: make game object persistent:
                    Object.DontDestroyOnLoad (go);
                }
                // trigger instantiation of other singletons
                Component c = MenuManager.SharedInstance;
                // ...
            }
        }
    
        GameObject main;
    
        public static MainComponentManger SharedInstance {
            get {
                if (instance == null) {
                    CreateInstance ();
                }
                return instance;
            }
        }
    
        public static T AddMainComponent <T> () where T : UnityEngine.Component {
            T t = SharedInstance.main.GetComponent<T> ();
            if (t != null) {
                return t;
            }
            return SharedInstance.main.AddComponent <T> ();
        }
    

    Now other singletons that want to register as Main component just look like:

    public class AudioManager : MonoBehaviour {
        private static AudioManager instance = null;
        public static AudioManager SharedInstance {
            get {
                if (instance == null) {
                    instance = MainComponentManger.AddMainComponent<AudioManager> ();
                }
                return instance;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a class that can take different types of value in
In the game engine I work with (Unity), a base class for every game
I have a class that takes many arguments to create. It’s a sort of
what is a good way to write unit tests with a LINQ to SQL
I'm working on developing a fairly robust 2D game engine as a base that
we want to use Unity for IOC. All i've seen is the implementation that
I want to write a business object layer in a way that makes each
I need a way to bind POJO objects to an external entity, that could
Good Afternoon. I have been working with Oracle Advanced Queues to create a messaging
I am writing unit tests for a PHP class that maintains users in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.