I am looking up a GO which is constantly returning “null” though I know for a fact it is there. Here is the scenario…
I lookup a GO if it is not there then Instantiate one, name and tag it. Now when I perform this action a second time the GO is still there, I can see it in the heirarchy but Find keeps returning “null”. The Find code looks like this:
var charGO : GameObject = GameObject.Find(characterInfo[c].CharacterName());
I have also tried some variations of it just like this (as I noticed with some of the GetComponent/AddComponent stuff you need quotes around your stringed variables but had the same results… That attempt looked like this:
var charGO : GameObject = GameObject.Find("" + characterInfo[c].CharacterName() + "");
The reason I am feeling this may be a bug or a bad limitation is if I replace this: characterInfo[c].CharacterName()
with something like this (the actual name of the GO):
var charGO : GameObject = GameObject.Find("Mackenzie");
It works as expected, unfortunately I do not have the luxury of knowing/guaranteeing the name.
Another thing you could try is parenting the instantiated GO to another GO that you always have a reference to, like MyCharacterParent, and then using MyCharacterParent.transform.FindChild(). If the transform is found, get the game object from it.