using UnityEngine.SceneManagement;
Debug.Log($"[Otto]: Doing a kickflip over the {type.Name}");
var fields = type.GetFields();
+ List<GameObject> sceneObjects = GetSceneObejcts();
for (int i = 0; i < fields.Length; i++)
var assetName = ParseName(fields[i].Name);
- if (SearchScene(command.context, assetName, fields[i])) fieldsSet++;
+ if (SearchScene(command.context, assetName, fields[i], sceneObjects)) fieldsSet++;
Debug.Log($"[Otto]: All done! I set {fieldsSet} fields");
Debug.Log($"[Otto]: Doing a kickflip over the {type.Name}");
var fields = type.GetFields();
+ List<GameObject> sceneObjects = GetSceneObejcts();
for (int i = 0; i < fields.Length; i++)
var assetName = ParseName(fields[i].Name);
- if (SearchScene(command.context, assetName, fields[i])) fieldsSet++;
+ if (SearchScene(command.context, assetName, fields[i], sceneObjects)) fieldsSet++;
Debug.Log($"[Otto]: All done! I set {fieldsSet} fields");
- static bool SearchScene(UnityEngine.Object target, string search, FieldInfo field)
+ static List<GameObject> GetSceneObejcts()
- //if we can't even find the obejct type in the scene, why search for it?
- //i.e. you won't find a float or audio clip in the scene!
- if (TypeNotSceneCompatible(field.FieldType)) return false;
List<GameObject> obj = new List<GameObject>();
SceneManager.GetActiveScene().GetRootGameObjects(obj);
var rootObj = new List<GameObject>(obj);
foreach (GameObject o in rootObj)
- for (int childIndex = 0; childIndex < o.transform.childCount; childIndex++)
- var t = o.transform.GetChild(childIndex);
- if (!obj.Contains(t.gameObject)) obj.Add(t.gameObject);
+ GetChildren(ref obj, o.transform);
+ static bool SearchScene(UnityEngine.Object target, string search, FieldInfo field, List<GameObject> obj)
+ //if we can't even find the obejct type in the scene, why search for it?
+ //i.e. you won't find a float or audio clip in the scene!
+ if (TypeNotSceneCompatible(field.FieldType))
- object targetObject = obj.Find(x => x.name.Contains(search));
+ object targetObject = obj.Find(x =>
+ var s = search.Split(' ');
+ return s.All(x.name.Contains);
if (!field.FieldType.Name.Contains("GameObject"))
+ static void GetChildren(ref List<GameObject> l, Transform t)
+ if (!l.Contains(t.gameObject)) l.Add(t.gameObject);
+ for (int childIndex = 0; childIndex < t.childCount; childIndex++)
+ var child = t.GetChild(childIndex);
+ if (!l.Contains(child.gameObject))
+ l.Add(child.gameObject);
+ if (child.childCount > 0)
+ var r = new List<GameObject>();
+ GetChildren(ref r,child);
+ foreach(GameObject g in r) if(!l.Contains(g))l.Add(g);
static string ParseName(string name)
var parsedName = String.Join(" ", Regex.Split(name, @"(?<!^)(?=[A-Z])"));