Hi all, I can't seem to figure out what I have done wrong. I made a generic Singleton Object like so: Code (CSharp): using UnityEngine; public class Singleton<T> : MonoBehaviour where T : Component { private static T instance; public static T Instance { get { if (instance == null) { instance = FindObjectOfType<T>(); if (instance == null) { GameObject obj = new GameObject(); obj.name = typeof(T).Name; instance = obj.AddComponent<T>(); } } return instance; } } protected virtual void Awake() { if (instance == null) { instance = this as T; } else { Destroy(gameObject); } } } Afterward I created a GameManager class: Code (CSharp): using UnityEngine; public class GameManager : Singleton<GameManager> { [SerializeField] private float gameTimer; public float GameTimer => gameTimer; protected override void Awake() { base.Awake(); Debug.Log("Started Game manager"); } private void Update() { gameTimer -= Time.deltaTime; } } My problem is that the update method on the GameManager is never being called. and it is attached to a game object in the active scene any ideas? Thanks in advance
My problem was that another script was calling the instance of the singleton in it's awake before. so it did the destory method and the object was destoryed. Took me a while to figure out what happens