From 93e35ddc976a4ea8247c145c6d49ba61b6451516 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 21 Jul 2022 16:48:41 -0700 Subject: [PATCH] do what detail builder does and remove all children with the path --- NewHorizons/Handlers/PlanetCreationHandler.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 2bfb3532..80f8381b 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -273,13 +273,23 @@ namespace NewHorizons.Handlers UpdateBodyOrbit(body, go); } - if (body.Config.removeChildren != null && body.Config.removeChildren.Length > 0) + if (body.Config.removeChildren != null) { - foreach (var child in body.Config.removeChildren) + var goPath = go.transform.GetPath(); + var transforms = go.GetComponentsInChildren(true); + foreach (var childPath in body.Config.removeChildren) { - // We purposefully use GameObject.Find here because we don't want to find inactive things. - // If you were to try and disable two children with the same name, if we were finding inactive then we'd disable the first one twice - Delay.FireInNUpdates(() => GameObject.Find(go.name + "/" + child)?.SetActive(false), 2); + // Multiple children can have the same path so we delete all that match + var path = $"{goPath}/{childPath}"; + + var flag = true; + foreach (var childObj in transforms.Where(x => x.GetPath() == path)) + { + flag = false; + childObj.gameObject.SetActive(false); + } + + if (flag) Logger.LogWarning($"Couldn't find \"{childPath}\"."); } }