Struct variable of type struct array initializing

Im having an issue with my struct. Im working on a implementation of the Monte Carlo Tree Search and i
created a struct called Node which has specific variables.
Now i need to store parent as well as child objects of type node. Since a node can be a parent for other nodes, but also child of a node this is important.

System.Serializable]
    public struct Node
    {

        public Transform[,] CurrentField_V;
        public Transform[,] CurrentField_H;
        public Transform[,] CurrentField_Boxes;
        public Node [] nodeChildren;
        public Node [] parent;
        public int result;
        public bool isTerminal;
        public bool alreadyChecked;
        public int y;
        public int x;
        public int visitTimes;



//THIS IS WERE THE ISSUE IS

 public Node Expand(Node v)
    {
       
        Debug.Log("Start EXPANSION");
        //create a new node
        Node newNode = new Node();
        newNode.parent[0] = v; //---------> NULL REFERENCE EXCEPTION
        newNode.CurrentField_V = v.CurrentField_V;
        newNode.CurrentField_H = v.CurrentField_H;
        v.nodeChildren[counter] = newNode;//---------> NULL REFERENCE EXCEPTION
        newNode.visitTimes++;

  
    }

does anyone have a clue how i can solve this issue?

A few thoughts:

  • Why would you use a struct for a Node instead of a class? (With a class you can you inheritance to force and implementation of Expand. That way you can decouple the MCTS logic from the actual search space.)
  • Why use an array for parent? There should only be one parent.
  • Expand should have no parameters and (optionally) no return type. It should expand itself into nodeChildren. (And optionally return that array.)
  • Make things easier for yourself by using a List for the children instead of an array.