List Problem

So I have function that simply is suppose to add stuff to it however when i test it after in the function im getting a null object?!?!?!? Please help!! from the log i get null then 121.

        public List<PathNode> NodeList;
        public int size;
        public GameObject Node;
        public void createNodeGrid()
        {
            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 PathNode;
                    NodeList.Add(tmp);
                    
                }
            }
            Debug.Log(NodeList[0]);
            size = NodeList.Count;
            Debug.Log(size);
           
        }

You get back what you instantiate - you can’t just use “as” on it. Use GetComponent.

tmp= (Instantiate(Node, new Vector3(i, 20, k), Quaternion.identity) as GameObject).GetComponent<PathNode>();

Whatever type of variable you are holding, you get back from Instantiate - so in your case a GameObject.