Quantcast
Viewing all articles
Browse latest Browse all 97

Problem with List

So Im calling a function in a class called PathNode, of an instantiated object. I later then call that same class but a different function that sets a value from that list. However im testing the count of the list in this function and getting 0, because im getting null reference. Not sure what im doing wrong!! Please help!! //AIUpdate Class public List NodeList; public GameObject Node; public PathNode testNode; void Start () { NodeList = new List(); } void Update() { testNode = NodeList[0]; testNode.setMoverStart(); } public void createNodeGrid() { int val = 0; for(int i=0;i<=2000;i+=200) { for(int k=0;k<=2000;k+=200) { PathNode tmp; tmp= (Instantiate(Node, new Vector3(i, 20, k), Quaternion.identity) as GameObject).GetComponent(); NodeList.Add(tmp); } } createLinks(); } public void createLinks() { int index = 0; NodeList[index].addLinkedNode(NodeList[8].gameObject); index++; NodeList[index].addLinkedNode(NodeList[7].gameObject); index++; NodeList[index].addLinkedNode(NodeList[6].gameObject); index++; NodeList[index].addLinkedNode(NodeList[5].gameObject); index++; NodeList[index].addLinkedNode(NodeList[5].gameObject); index++; NodeList[index].addLinkedNode(NodeList[3].gameObject); index++; NodeList[index].addLinkedNode(NodeList[2].gameObject); index++; NodeList[index].addLinkedNode(NodeList[1].gameObject); index++; NodeList[index].addLinkedNode(NodeList[0].gameObject); index++; } //PathNode Class public List linkedNodes; void Start () { linkedNodes = new List(); } public void setMoverStart() { Debug.Log(this.linkedNodes.Count);//get 0 } public void addLinkedNode(GameObject x) { this.linkedNodes.Add(x); Debug.Log(this.linkedNodes.Count);//get the true size }

Viewing all articles
Browse latest Browse all 97

Trending Articles