From 6945c0b6c7694fdbc765f006f7b6671dc4cd8f4f Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 13 Jul 2022 19:52:47 -0400 Subject: [PATCH] Stop any rigidbody from unparenting itself when deleting solar system --- NewHorizons/Handlers/PlanetDestructionHandler.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index 33ffbb39..73ed138b 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -3,6 +3,7 @@ using NewHorizons.Utility; using OWML.Utils; using System; using System.Collections.Generic; +using System.Linq; using UnityEngine; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Handlers @@ -30,12 +31,26 @@ namespace NewHorizons.Handlers "White Hole" }; + private static readonly string[] _suspendBlacklist = new string[] + { + "Player_Body", + "Ship_Body" + }; + public static void RemoveSolarSystem() { // Stop the sun from killing the player var sunVolumes = SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN"); sunVolumes.SetActive(false); + foreach (var ow in GameObject.FindObjectsOfType()) + { + if (ow._origParent != null && (ow._origParentBody != null || ow._simulateInSector != null) && ow.transform.GetComponent() == null && !ow._suspended && !_suspendBlacklist.Contains(ow.gameObject.name)) + { + ow.Suspend(); + } + } + foreach (var name in _solarSystemBodies) { var ao = AstroObjectLocator.GetAstroObject(name);