List<List<Transform>> in inspector

Okay straight to the point.

I need to be able to see and save a List<List> in the inspector/editor

I need to do this because I need a 2 dimensional dynamic array, and the tool I wrote for the Editor saves the values of a certain object in the prefab of that object,

some visual help:

this is the object I need to save the List<List> to:

public class Pather : MonoBehaviour
{
	Transform car;
	
	public List<List<Transform>> roads = new List<List<Transform>>();	
	
	public static int usingRoad = 0;
	Transform target;
	public int PATHLENGTH = 999;
	public bool move = true;
	public int speed= 20;
	public Vector3 heightDifference = new Vector3(0,5,0);
	enum RoadSide{Out,Inner}
	
	RoadSide roadSide = RoadSide.Inner;
	
	Vector3 finalPosObj;
	void Start()
	{
		if(roads.Count > Pather.usingRoad)
		{
			target = roads[Pather.usingRoad][0];
			transform.position = target.position-heightDifference;
		}
		else
		{
			throw new UnityException("No Begin Path found (Empty array in Car Inspector?)");	
		}
	}
}

And I do this from the editorwindow with this: //note this is not the whole code

public class CarPath : EditorWindow 
{
[HideInInspector]
	static public int currentPathNumber = 0;
	[HideInInspector]
 	static public Transform car;
	[HideInInspector]
	static public bool carSelected = false;
	[HideInInspector]
	static public Pather p;
	[HideInInspector]
	List<Transform> road = new List<Transform>();
	
	[MenuItem ("Window/CarPath")]
	static void Init ()
	{
		CarPath window = (CarPath)EditorWindow.GetWindow (typeof (CarPath));
	}
void AddToPatherRTycoon(Transform t)
	{
		if(t.tag != "Bend2x90"  t.tag != "Bend3x90")
		{
			RaycastHit hit0;
			if(Physics.Raycast(t.position,Vector3.forward,out hit0,t.collider.bounds.size.x/2+1))
			{
				if(GUI.Button(new Rect(20,0,20,20),"F"))
				{
					while(CarPath.p.roads.Count < Pather.usingRoad+1)
					{
						CarPath.p.roads.Add(new List<Transform>());	
					}
					if(CarPath.p.roads[Pather.usingRoad].Count > 0)
					{
						SetTurn(CarPath.p.roads[Pather.usingRoad][CarPath.p.roads[Pather.usingRoad].Count-1],t,hit0.transform);
					}
					
					CarPath.p.roads[Pather.usingRoad].Add(t); //<-----------------   see this
					Selection.activeTransform = car;
					EditorApplication.ExecuteMenuItem("GameObject/Apply Changes To Prefab");   //<-----------------   see this  (this won't work because the List<List<Transform>> is not showing in the inspector thus it won't save it to the current prefab, (all changes are lost when I press Play))
					Selection.activeTransform = hit0.transform;
				}

}		
}
}
}

note: EditorApplication.ExecuteMenuItem(“GameObject/Apply Changes To Prefab”); DOES work with the other showable values… so if I edit a integer with the function and use this… it will get saved and stay when I press Play

So can anyone help me get this to work?..
Basically I figured out… If I can manually add a List to the List<List> in the inspector and then edit loose Transforms in for example List[0][×] it will get saved and stay that way…

Unity does not serialize multidimensional arrays. You could however create a class representing what the List represents in List<List>.

[System.Serializable]
public class Road {
     public List<Transform> list;
}

public class Pather : MonoBehaviour
{
    Transform car;  
    // public List<List<Transform>> roads = new List<List<Transform>>();       

    // List<Transform> is replaced with the Road class which contains a list
    // of Transforms and is serialized so it shows in the inspector.
    public List<Road> roads = new List<List<Road>>();       
    public static int usingRoad = 0;
    Transform target;
    public int PATHLENGTH = 999;
    public bool move = true;
    public int speed= 20;
    public Vector3 heightDifference = new Vector3(0,5,0);
    enum RoadSide{Out,Inner}
    RoadSide roadSide = RoadSide.Inner;
    Vector3 finalPosObj;

    void Start()
    {
        if(roads.Count > Pather.usingRoad)
        {
            // target = roads[Pather.usingRoad][0];

            // Instead of accessing the Transform in the list at roads[Pather.usingRoad]
            // the Transform is accessed through the Road class's Transform list.
            target = roads[Pather.usingRoad].list[0];
            transform.position = target.position-heightDifference;
        }
        else
        {
            throw new UnityException("No Begin Path found (Empty array in Car Inspector?)");    
        }
    }
}

Haven’t tested it but should work as far as serializing the Transform list you want to edit in the inspector.

Perfect! It works!, Thanks very much,

Seems I’ll need to look a bit more into serializing…

(also typo with the serializable)
[System.Serializable] not [System.Serializeable] (for the other people who might see this post and needed the same)

Yeah I’m hopeless without Intelli-sense, I’ll edit the post so it doesn’t cause issues for anyone who uses it. Unity’s serialization is a pain, but it’s never stopped me from doing what I need to do so I don’t mind. It just takes some researching and practice to get the hang of. Glad I could help, good luck!

Always those things you’ve read once or twice about it and then forgot it… only to have it needed at a much later time…

(Also ended up with like 200 lines (spread over a few files) I had to edit to get it working again but it does work.