Object reference not set to an instance of an object.

So I have no idea why I get this error, I have declared a HashSet, and then I check if it contains a certain Vector2 variable, that variable does have a reference, I tried to debug it and it works, I guess HashSet has something to do with it. So the enter code here code looks something like this…

HashSet<Vector2> exists;
...
Vector2 cords = new Vector2((float)x, (float)z);
if(!exists.Contains(cords)) // <- error is on this line over here
{
     ...
}
I'd really appreciate any kind of help, thanks a lot.

I believe the issue is that you have defined the member HashSet but not created it. You should try:

        HashSet<Vector2> exists = new HashSet<Vector2>();