I have a prefab called MapInfo, with a script attached, “MapInfo.cs”. I also have a prefab called Data that I assign to a data prefab.
MapInfo.cs:
public GameObject data_prefab; //the prefab is assigned here through the inspector
void Start(){
DataInit();
}
void DataInit(){
Instantiate(data_prefab,Vector3.zero,Quaternion.identity);
}
This works just fine. Where the problem lies is in the script, Data.cs, that’s attached to the data_prefab prefab.
Data.cs:
void Awake(){
GameObject go = GameObject.Find("MapInfo");
if(go==null) Debug.Log ("Can't find MapInfo");
}
When the data prefab is instantiated from MapInfo.cs in the DataInit function, its script tries to find the MapInfo GameObject that instantiated it, and it prints that Debug line every single time. Is it a mistake trying to find this GameObject? It must be in existence considering the Data script doesn’t start without MapInfo creating it! I’ve tried FindWithTag as well with an appropriate tag assigned, no such luck. Has anyone else experienced this?