// Helps initialize a system when triggered SystemBase CreateSubsystem <T>() where T : SystemBase { T foundSystem = FindObjectOfType <T>(); if (foundSystem) { if (!foundSystem.IsInitialized) { Type foundSysType = typeof(T); DEBUG.Log(foundSysType.FullName + " detected in scene, this is not good as the data could be stale. Will use it for now ", Warning_Types.Warning); foundSystem.Initialize(); foundSystem.IsInitialized = true; foundSystem.gameObject.transform.SetParent(null); DontDestroyOnLoad(foundSystem.gameObject); } foundSystem.name = foundSystem.name + "_FOUND"; Systems.Add(foundSystem); return(foundSystem.GetComponent <SystemBase>()); } // Use reflection to get the prefab name Type systemType = typeof(T); if (systemType == null) { DEBUG.Log("Could not determine the system type for given system", Warning_Types.Error); return(null); } GameObject system = Instantiate(Resources.Load("Managers/" + systemType.FullName) as GameObject, null); DontDestroyOnLoad(system); system.name = system.name.Replace("(Clone)", "_APP"); SystemBase systemBase = system.GetComponent <SystemBase>(); if (systemBase != null) { systemBase.Initialize(); systemBase.IsInitialized = true; systemBase.gameObject.transform.SetParent(transform); } Systems.Add(system.GetComponent <SystemBase>()); DEBUG.Log(systemType.FullName + " created...", Warning_Types.Good); return(system.GetComponent <SystemBase>()); }