{"author_link":"\/users\/ausstein","author_name":"Ausstein","author_uid":"ausstein","comments":[],"epoch":1759525260,"event":"LD58","format":"md","ldjam_node_id":419230,"likes":6,"metadata":{"p_key":"196206","p_author":"Ausstein","p_authorkey":"1140199","p_urlkey":"427575","p_title":"I'm IN! 15 in a row!","p_cat":"LDJam ","p_event":"LD58","p_time":"1759525260","p_likes":"6","p_comments":"0","p_status":"WAYBACK","us_key":"1140199","us_name":"Ausstein","us_username":"ausstein","event_start":"1759449600","event_key":"112","event_name":"Ludum Dare 58"},"node":{"_collation":{"body_sanitizer":"TextUtils::SanitizeHTML via existing importer","event":"LD58","removed_author":false},"_superparent":415614,"_trust":9,"author":140199,"body":"Joining for my 15th LD in a row!\n\nLast time I shared a version of the Singleton Pattern as a script and I still think this is one of the Best Helper Classes I use in almost all of my Unity Projects, So I'll just copy it again!\n\nAs a little bonus, I wanted to share a helpful Unity tip that I've been using in my last few projects \u2014 especially handy during a game jam when speed matters.\n\nIt\u2019s about the **Singleton pattern**, which is super useful for scripts where you only ever want one instance in your game (like your `SceneManager`, `AudioManage`r, etc.).\n\nI used to write the singleton logic manually in each of these scripts. But now, I use this handy base class instead \u2014 whenever I want singleton behavior, I just make my script derive from `Singleton<T>`!\n\nFor example:\n\n`public class SceneManager : Singleton<SceneManager>`\n\ninstead of \n\n`public class SceneManager : MonoBehaviour`\n\n\nI hope this is helpful to someone out there, here is the script:\n```\nusing UnityEngine;\n\npublic class Singleton<T> : MonoBehaviour where T : MonoBehaviour\n\n{\n\n    private static T _instance;\n\n    public static T Instance\n    {\n        get\n        {\n            if (_instance == null)\n            {\n                \/\/ Search for existing instance.\n                _instance = FindFirstObjectByType<T>();\n\n                \/\/ Create new instance if one doesn't already exist.\n                if (_instance == null)\n                {\n                    \/\/ Ensure that there's a GameObject to attach the singleton to.\n                    var singletonObject = new GameObject();\n                    _instance = singletonObject.AddComponent<T>();\n                    singletonObject.name = typeof(T).ToString() + \" (Singleton)\";\n\n                    \/\/ Make sure the singleton persists across scenes.\n                    DontDestroyOnLoad(singletonObject);\n                }\n            }\n            return _instance;\n        }\n    }\n\n    protected virtual void Awake()\n    {\n        if (_instance == null)\n        {\n            _instance = this as T;\n            DontDestroyOnLoad(this.gameObject);\n        }\n        else\n        {\n            Destroy(gameObject);\n        }\n    }\n}\n```\nGood luck to everyone jamming!","comments":2,"comments-timestamp":"2025-10-03T21:41:03Z","created":"2025-10-03T20:59:00Z","files":[],"files-timestamp":0,"id":419230,"love":6,"love-timestamp":"2025-10-03T23:52:33Z","meta":[],"modified":"2025-10-03T23:52:33Z","name":"I'm IN! 15 in a row!","node-timestamp":"2025-10-03T21:01:00Z","parent":415758,"parents":[1,5,9,415614,415758],"path":"\/events\/ludum-dare\/58\/ghost-collector-1\/im-in-15-in-a-row","published":"2025-10-03T21:01:00Z","scope":"public","slug":"im-in-15-in-a-row","subsubtype":"","subtype":"","type":"post","version":1319025},"node_metadata":{"n_key":"419230","n_urlkey":"427575","n_parent":"415758","n_path":"\/events\/ludum-dare\/58\/ghost-collector-1\/im-in-15-in-a-row","n_slug":"im-in-15-in-a-row","n_type":"post","n_subtype":"","n_subsubtype":"","n_author":"140199","n_created":"1759525140","n_modified":"1759535553","n_version":"1319025","n_status":"WAYBACK"},"source_url":"https:\/\/ldjam.com\/events\/ludum-dare\/58\/ghost-collector-1\/im-in-15-in-a-row","text":"Joining for my 15th LD in a row!\n\nLast time I shared a version of the Singleton Pattern as a script and I still think this is one of the Best Helper Classes I use in almost all of my Unity Projects, So I'll just copy it again!\n\nAs a little bonus, I wanted to share a helpful Unity tip that I've been using in my last few projects \u2014 especially handy during a game jam when speed matters.\n\nIt\u2019s about the **Singleton pattern**, which is super useful for scripts where you only ever want one instance in your game (like your `SceneManager`, `AudioManage`r, etc.).\n\nI used to write the singleton logic manually in each of these scripts. But now, I use this handy base class instead \u2014 whenever I want singleton behavior, I just make my script derive from `Singleton<T>`!\n\nFor example:\n\n`public class SceneManager : Singleton<SceneManager>`\n\ninstead of \n\n`public class SceneManager : MonoBehaviour`\n\n\nI hope this is helpful to someone out there, here is the script:\n```\nusing UnityEngine;\n\npublic class Singleton<T> : MonoBehaviour where T : MonoBehaviour\n\n{\n\n    private static T _instance;\n\n    public static T Instance\n    {\n        get\n        {\n            if (_instance == null)\n            {\n                \/\/ Search for existing instance.\n                _instance = FindFirstObjectByType<T>();\n\n                \/\/ Create new instance if one doesn't already exist.\n                if (_instance == null)\n                {\n                    \/\/ Ensure that there's a GameObject to attach the singleton to.\n                    var singletonObject = new GameObject();\n                    _instance = singletonObject.AddComponent<T>();\n                    singletonObject.name = typeof(T).ToString() + \" (Singleton)\";\n\n                    \/\/ Make sure the singleton persists across scenes.\n                    DontDestroyOnLoad(singletonObject);\n                }\n            }\n            return _instance;\n        }\n    }\n\n    protected virtual void Awake()\n    {\n        if (_instance == null)\n        {\n            _instance = this as T;\n            DontDestroyOnLoad(this.gameObject);\n        }\n        else\n        {\n            Destroy(gameObject);\n        }\n    }\n}\n```\nGood luck to everyone jamming!","title":"I'm IN! 15 in a row!","wayback_source":[]}