From 21f9d3a5e7ca4cc71f8e28bac1fa8345cceb1540 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 30 Jun 2022 21:52:56 -0400 Subject: [PATCH] Only find active objects when doing RemoveChildren --- NewHorizons/Builder/Props/DetailBuilder.cs | 4 +++- NewHorizons/Handlers/PlanetCreationHandler.cs | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 19025ad6..cf71a50c 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -41,7 +41,9 @@ namespace NewHorizons.Builder.Props { foreach (var childPath in detail.removeChildren) { - var childObj = detailGO.transform.Find(childPath); + // 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 + var childObj = GameObject.Find($"{SearchUtilities.GetPath(detailGO.transform)}/{childPath}"); if (childObj != null) childObj.gameObject.SetActive(false); else Logger.LogWarning($"Couldn't find {childPath}"); } diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index b67661d8..55d7db88 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -252,6 +252,8 @@ namespace NewHorizons.Handlers { foreach (var child 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 Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => GameObject.Find(go.name + "/" + child)?.SetActive(false), 2); } }