Argument Out of Range On a List

Hi, I am making my own pathfinding solution to fit my game and so far it works but I just added a new function in my code and my List is not being properly adjusted.
Here is the code:

void findPathOfSplitNodes() 
    {
        splitNodesPath = new List<List<GameObject>>();

        //We find the path starting at each split node and then save that path in a list
        for(int i = 0; i < allSplitNodes.Count; i++)
        {
            splitNodesPath *= new List<GameObject>();*

splitNodesPath.Add(goThroughPath(allSplitNodes[0]));
}
}
The problem is with splitNodesPath _= goThroughPath(allSplitNodes*);*
Thanks for the help!_

2 Answers

2

It doesn’t look like you have given splitNodesPath a size. Does changing line 8 to the following still cause and error?

splitNodesPath *= new List<GameObject>();*

If so try changing your code to
splitNodesPath.Add(goThroughPath(allSplitNodes*));*

I updated my code to fit yours.... still does not work.

What exactly di you change to?

I updated my code. It still does not work.

Remove line 8 that was a test to see where the error was. If using new causes an error then replace with the add line. Here is the code I intended you write in my answer void findPathOfSplitNodes() { splitNodesPath = new List<List<GameObject>>(); //We find the path starting at each split node and then save that path in a list for(int i = 0; i < allSplitNodes.Count; i++) { splitNodesPath.Add(goThroughPath(allSplitNodes*));* } }

Hi, I have a question. Why did you initiate i-th entry of splitNodesPath in the for loop again? You have initiated splitNodesPath before the for loop. Maybe you can delete

splitNodesPath *= new List<GameObject>();*

Probably your goThroughPath(allSplitNodes_) is add to the (i+1)-th entry? Or you can check i-th entry of splitNodesPath with Debug.Log to print it._