I am attempting to copy the contents of one list into another. On the first iteration I get an "Argument out of range" error.
static List<Building> SaveBuildings(List<Building> buildings)
{
if (buildings.Count == 0)
return null;
Debug.Log("Save Buildings Count: " + buildings.Count);
List<Building> records = new List<Building>();
for (int i = 1; i < buildings.Count; i++)
{
Debug.Log("i: " + buildings[i].name);
records[i] = buildings[i].GetRecord();
}
return records;
}
The offending line is: records[i] = buildings[i].GetRecord();
This code "Debug.Log("Save Buildings Count: " + buildings.Count);" shows that the list is not empty. The following code "List records = new List();" instantiates a new list to be used.
My understanding is that everything should work well, but when I run the code this line fires "Debug.Log("i: " + buildings[i].name);" and then the error.
I've changed "int i" to be "0" and "i < buildings.Count" to "i <= buildings.Count" with i being 1 and 0. Same results.
I need fresh eyes to find the error lol thank you for your help