diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 51ddbac6..69e88d03 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -165,7 +165,7 @@ namespace NewHorizons.Handlers { var ao = existingPlanet.GetComponent(); if (ao != null) Delay.FireInNUpdates(() => PlanetDestructionHandler.RemoveBody(ao), 2); - else Delay.FireInNUpdates(() => existingPlanet.SetActive(false), 2); + else Delay.FireInNUpdates(() => PlanetDestructionHandler.DisableBody(existingPlanet, false), 2); } else if (body.Config.isQuantumState) { diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index 68d45537..ee3b9535 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -43,14 +43,6 @@ namespace NewHorizons.Handlers var sunVolumes = SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN"); sunVolumes.SetActive(false); - foreach (var ow in CenterOfTheUniverse.s_rigidbodies) - { - 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); @@ -219,12 +211,44 @@ namespace NewHorizons.Handlers } } - private static void DisableBody(GameObject go, bool delete) + private static bool CanSuspend(OWRigidbody rigidbody, string name) + { + if (rigidbody.transform.name == name) return true; + if (rigidbody._origParentBody == null) return false; + return CanSuspend(rigidbody._origParentBody, name); + } + + internal static void DisableBody(GameObject go, bool delete) { if (go == null) return; Logger.LogVerbose($"Removing [{go.name}]"); + OWRigidbody rigidbody = go.GetComponent(); + if (rigidbody != null) + { + string name = rigidbody.transform.name; + foreach (var ow in CenterOfTheUniverse.s_rigidbodies) + { + if (_suspendBlacklist.Contains(ow.transform.name)) continue; + if (ow.GetComponent() != null) continue; + if (ow._origParentBody != null) + { + if (CanSuspend(ow, name)) + { + ow.Suspend(); + } + } + else if (ow._simulateInSector != null) + { + if (CanSuspend(ow._simulateInSector.GetAttachedOWRigidbody(), name)) + { + ow.Suspend(); + } + } + } + } + if (delete) { GameObject.Destroy(go);