Skip to content

Instantly share code, notes, and snippets.

@eslof
eslof / SingletonMonoBehaviour.cs
Created June 6, 2021 18:10 — forked from ErikOG/SingletonMonoBehaviour.cs
Most singletons out there will 'destroy' other instances, I think there shouldn't be more than one instance of it to begin with, if there are we just want to find out about it so we can fix the core of the problem and not just the symptom.
using UnityEngine;
#if UNITY_EDITOR || DEBUG
using System;
using UnityEngine.SceneManagement;
#endif
public class SingletonMonoBehaviour<T> : MonoBehaviour where T : MonoBehaviour {
private static T _instance = null;
public static T Instance {