let Find also recursively find an inactive object

This commit is contained in:
JohnCorby 2022-07-09 16:49:39 -07:00
parent 5ca76f3187
commit 2407ac9fba

View File

@ -90,7 +90,7 @@ namespace NewHorizons.Utility
/// <summary> /// <summary>
/// finds active or inactive object by path, /// finds active or inactive object by path,
/// or recursively finds an active object by name /// or recursively finds an active or inactive object by name
/// </summary> /// </summary>
public static GameObject Find(string path, bool warn = true) public static GameObject Find(string path, bool warn = true)
{ {
@ -113,8 +113,11 @@ namespace NewHorizons.Utility
go = root.FindChild(childPath); go = root.FindChild(childPath);
if (go == null) if (go == null)
{ {
if (warn) Logger.LogWarning($"Couldn't find child object in path ({path})"); var name = names.Last();
return null; if (warn) Logger.LogWarning($"Couldn't find object in path ({path}), will look for potential matches for name {name}");
// find resource to include inactive objects
// also includes prefabs but hopefully thats okay
go = FindResourceOfTypeAndName<GameObject>(name);
} }
} }