So im instantiating a prefab with a script attached to it. inside the prefab script it holds a List variable. right now Im testing to figure out what the problem is, but what seems to be happening is the data is being stored during the Awake function, but when the update begins all of that goes out the door. Is there any way to make it so this doesnt happen???
//Update Class
public List NodeList ;
public void Awake()
{
NodeList = new List();
PrefabInst tmp = (Instantiate(Node, new Vector3(0, 20, 0), Quaternion.identity) as GameObject).GetComponent();
PrefabInst tmp2 = (Instantiate(Node, new Vector3(20, 20, 20), Quaternion.identity) as GameObject).GetComponent();
tmp.addLinkedNode(tmp2);
tmp2.addLinkedNode(tmp);
NodeList.Add(tmp);
NodeList.Add(tmp2);
Debug.Log(NodeList[0].linkedNodes[0]);//Not null - good
Debug.Log(NodeList[1].linkedNodes[0]);//not null - good
NodeList[0].setMoverStart();//give size of 1 - good
NodeList[1].setMoverStart();//give size of 1 - good
}
public void Update()
{
Debug.Log(NodeList[0].linkedNodes[0]);//is null - ??bad??
Debug.Log(NodeList[1].linkedNodes[0]);//is null - ??bad??
NodeList[0].setMoverStart();//give size of 0 - ??bad??
NodeList[1].setMoverStart();//give size of 0 - ??bad??
}
//PrefabInst class
public List NodeList ;
public void setMoverStart()
{
Debug.Log(this.linkedNodes.Count);
}
↧