Added backup for prop searching (very costly tho)

This commit is contained in:
Nick J. Connors 2022-02-04 12:38:13 -05:00
parent 8e36f5b479
commit fd8a95bb28

View File

@ -100,9 +100,10 @@ namespace NewHorizons.Utility
public static GameObject Find(string path) public static GameObject Find(string path)
{ {
var go = GameObject.Find(path); var go = GameObject.Find(path);
if(go == null)
var names = path.Split(new char[] { '\\', '/' });
if (go == null)
{ {
var names = path.Split(new char[] { '\\', '/' });
// Get the root object and hope its the right one // Get the root object and hope its the right one
var root = GameObject.Find(names[0]); var root = GameObject.Find(names[0]);
@ -143,6 +144,13 @@ namespace NewHorizons.Utility
go = t.gameObject; go = t.gameObject;
} }
if(go == null)
{
var name = names.Last();
Logger.LogWarning($"Couldn't find object {path}, will look for potential matches for name {name}");
go = FindObjectOfTypeAndName<GameObject>(name);
}
return go; return go;
} }
} }