Only find active objects when doing RemoveChildren

This commit is contained in:
Nick 2022-06-30 21:52:56 -04:00
parent dffb767fc8
commit 21f9d3a5e7
2 changed files with 5 additions and 1 deletions

View File

@ -41,7 +41,9 @@ namespace NewHorizons.Builder.Props
{ {
foreach (var childPath in detail.removeChildren) 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); if (childObj != null) childObj.gameObject.SetActive(false);
else Logger.LogWarning($"Couldn't find {childPath}"); else Logger.LogWarning($"Couldn't find {childPath}");
} }

View File

@ -252,6 +252,8 @@ namespace NewHorizons.Handlers
{ {
foreach (var child in body.Config.removeChildren) 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); Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => GameObject.Find(go.name + "/" + child)?.SetActive(false), 2);
} }
} }