diff --git a/SpaceWarp/API/SpaceWarpManager.cs b/SpaceWarp/API/SpaceWarpManager.cs index 6bf21b71..84ed2725 100644 --- a/SpaceWarp/API/SpaceWarpManager.cs +++ b/SpaceWarp/API/SpaceWarpManager.cs @@ -68,7 +68,7 @@ private void Initialize() public void InitializeConfigManager() { GameObject confManagerObject = new GameObject("Configuration Manager"); - DontDestroyOnLoad(confManagerObject); + Persist(confManagerObject); confManagerObject.AddComponent(); confManagerObject.SetActive(true); @@ -522,7 +522,7 @@ private void InitializeModObject(string modName, ModInfo info, Type mainModType) try { ModLocator.Add(modComponent); - DontDestroyOnLoad(modObject); + Persist(modObject); modComponent.Initialize(); } catch(Exception exception) @@ -557,7 +557,7 @@ internal void InvokePostInitializeModsAfterAllModsLoaded() private void InitModUI() { GameObject modUIObject = new GameObject("Space Warp Mod UI"); - DontDestroyOnLoad(modUIObject); + Persist(modUIObject); modUIObject.transform.SetParent(transform.parent); ModListUI = modUIObject.AddComponent(); @@ -565,7 +565,7 @@ private void InitModUI() modUIObject.SetActive(true); GameObject consoleUIObject = new GameObject("Space Warp Console"); - DontDestroyOnLoad(consoleUIObject); + Persist(consoleUIObject); consoleUIObject.transform.SetParent(transform.parent); SpaceWarpConsole con = consoleUIObject.AddComponent(); consoleUIObject.SetActive(true); @@ -576,7 +576,7 @@ private void InitModUI() public T RegisterGameToolbarMenu(string text, Sprite icon, string id) where T : ToolbarMenu { GameObject toolBarUIObject = new GameObject($"Toolbar: {id}"); - DontDestroyOnLoad(toolBarUIObject); + Persist(toolBarUIObject); ToolbarMenu menu = toolBarUIObject.AddComponent(); menu.Name = text; toolBarUIObject.transform.SetParent(transform.parent); @@ -585,6 +585,12 @@ public T RegisterGameToolbarMenu(string text, Sprite icon, string id) where T return menu as T; } + public static void Persist(GameObject toPersist) + { + DontDestroyOnLoad(toPersist); + toPersist.tag = "Game Manager"; + } + private void LoadAllButtons() { foreach (var button in _buttonsToBeLoaded) diff --git a/SpaceWarp/StartupManager.cs b/SpaceWarp/StartupManager.cs index caf1eb33..fa0858be 100644 --- a/SpaceWarp/StartupManager.cs +++ b/SpaceWarp/StartupManager.cs @@ -43,7 +43,7 @@ public static void OnGameStarted() private static void CreateSpaceWarpManager() { GameObject spaceWarp = new GameObject("Space Warp"); - Object.DontDestroyOnLoad(spaceWarp); + SpaceWarpManager.Persist(spaceWarp); SpaceWarpObject = spaceWarp.AddComponent(); spaceWarp.SetActive(true); // SpaceWarpObject.Initialize();