Nested lists of Vector3 and adding to them

I’m trying to create a generic list of generic lists to store Vector3 coordinates. I’m getting errors however when I try to add to it.

> ArgumentOutOfRangeException: Argument is out of range. Parameter name: index

As I understand it I’m trying to add an item to the list at an index that doesn’t exist. I’m not sure whether my list declaration is incorrect or whether I’m adding the data incorrectly.

Declaration:

var moveXYZ	: List.< List.<Vector3> >; moveXYZ = new List.< List.<Vector3> >();

I’ve tried various methods to populate the list with Vector3 values pulled from a data class I made to store all the animation data for the enemies in my game. I only have one line from below active at a time (I comment out the failures in case there’s something there that’s correct.)

moveXYZ*[j].Set(gcScript.ewData.moveXYZ[cwi, i, j]); // Autocompletes Set (as Vector3, not list), not Add*

moveXYZ*.Add(gcScript.ewData.moveXYZ[cwi, i, j]); // Doesn’t work*
moveXYZ[i,j].Add(gcScript.ewData.moveXYZ[cwi, i, j]); // Doesn’t work, no autocomplete on code either
Any ideas on how to fix this? I feel I’m probably missing something really basic on adding to lists in lists but I’ve not found any examples on how to do this. Just examples on declaring them.

What is gcScript.ewData.moveXYZ[cwi, i, j] - what type of thing is it? Is it a Vector3? Is it a List?

Your problem is one of these two things (in C#, because that’s what I use):

Either you need to properly declare the inner list:

List<List<Vector3> moveXYZ;
moveXYZ = new List<List<Vector3>>();
moveXYZ.Add(new List<Vector3>()); //now you actually have two lists initialized, the inner one and the outer one

Or if your gcScript thing is a List, you just need to add it:

moveXYZ.Add(gcScript.ewData.moveXYZ[cwi, i, j]); //dont add an index before the add