Object reference not set to an instance of an object in the PathFinder script

I’m looking at the code that was shown in the lecture and have compared it to my own and it looks exactly like what he has, yet i am still getting the error with the ExploreNeighbors function. Specifically it’s pointing to the if statement directly.

What i have is:

void ExploreNeighbors()
{
    List<Node> neighbors = new List<Node>();

    foreach(Vector2Int direction in directions)
    {
        Vector2Int neighborCoords = currentSearchNode.coordinates + direction;

       if(grid.ContainsKey(neighborCoords))
        {
            neighbors.Add(grid[neighborCoords]);

            //TODO remove after testing
            grid[neighborCoords].isExplored = true;
            grid[currentSearchNode.coordinates].isPath = true;
        }
    }            
            
}

What am I missing?

Seems that just typing out my question got me to solve it. I scanned through the rest of the files and saw that in the awake function it was not properly finding the object for the grid manager. Setting it properly solved the issue.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms