Making a list of list of nodes for Kruskal

I’m trying to do a Kruskal algorithm (pathfinding), but I’m having a problem when putting the nodes list in the list of list of nodes (each node is in a separate list and as the nodes connect, the lists are combined).

Here is my code:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Kruskal : MonoBehaviour {
	
	
	public List<List<Nodo>> bosque;
	public GameObject[] goNodos;
	public List<Nodo> nodos;
	
	
	void Start () {
		goNodos = GameObject.FindGameObjectsWithTag("Nodo");
		
		for (int i = 0; i < goNodos.Length; i++) {
			nodos.Add(goNodos*.GetComponent<Nodo>());*
  •  }*
    
  •  for (int i = 0; i < nodos.Count; i++) {*
    

bosque_.Add(nodos*); //It throws an error here. (NullReferenceException: Object reference not set to an instance of an object)
}*_

* }*

}
What am I doing wrong?

Where do you actually create your lists? So where do you actualy do

bosque = new List<List<Nodo>>();

and where do you fill the list with lists?

something like that:

bosque.Add(new List<Nodo>());
bosque.Add(new List<Nodo>());
bosque.Add(new List<Nodo>());

Lists don’t grow on trees, they have to be created :wink:

Great! Solved!
Is there any way to visualize it in the inspector?