NullReferenceException: When creating a graph
Hello,
I'm trying to create a graph containing all the tiles in my tile-based game. I've created a graph containing information about all of the tiles, and then a list per node in the graph, containing all neighboring nodes.
The error occurs when trying to add the neighboring nodes based on the current node in the graph. The function has the line:
graph[x, y].neighbours.Add(graph[x , y]);
With variations on x and y for each neighbor. (i.e. [x-1, y] and [x+1, y] to list neighbours on the same row).
The error brings me to the first instance of the line in bold, but commenting that line out would only cause the next instance of the code to display the same error.
The exact error states:
NullReferenceException: Object reference not set to an instance of an object MapManager.GeneratePathGraph ()
No object is however used in the entire function, so I don't understand what I'm expected to do to resolve this error.
.
Much appreciated,
TAG
I'm getting an error trying to upload a picture of the full function for reference. If this is needed, Ill answer with a link.
Your answer
![](https://koobas.hobune.stream/wayback/20220613002146im_/https://answers.unity.com/themes/thub/images/avi.jpg)