i am getting a null reference error saying the instance is not set to a reference of an object. ive been trying to figure out what im doing wrong but i cant find the problem. my code is the same as the instructor its saying line 34 is the problem which is the line with the if statement for neighborcoords
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pathfinder : MonoBehaviour
{
[SerializeField] Node currentSearchNode;
Vector2Int directions = {Vector2Int.right, Vector2Int.left, Vector2Int.up, Vector2Int.down};
GridManager gridManager;
Dictionary<Vector2Int, Node> grid;
void Awake()
{
gridManager = GetComponent<GridManager>();
if (gridManager != null )
{
grid = gridManager.Grid;
}
}
void Start()
{
ExploreNeighbors();
}
void ExploreNeighbors()
{
List<Node> neighbors = new List<Node>();
foreach (Vector2Int directions in directions)
{
Vector2Int neighborCoords = currentSearchNode.coordinates + directions;
if (grid.ContainsKey(neighborCoords)) < this is the line unity is saying is the problem
{
neighbors.Add(grid[neighborCoords]);
}
//Remove after testing
grid[neighborCoords].isExplored = true;
grid[currentSearchNode.coordinates].isPath = true;
}
}
}