Hello Guys,
i cant find the Error in my Code. It says “Object reference not set to an instance of an object” but i dont know why.
To understand my code i explain what it should do.
With
public GameObject Waypoint;
private void CreatePath(List<Vector2Int> pathPoints)
{
foreach (Vector2Int pathPoint in pathPoints)
{
int neighbourValue = pathGenerator.getNeighbourValue(pathPoint.x, pathPoint.y);
GameObject pathPointTile = pathCells[neighbourValue].cellPrefab;
GameObject pathTile = Instantiate(pathPointTile, new Vector3(pathPoint.x, 0f, pathPoint.y), Quaternion.identity);
pathTile.transform.Rotate(0f, pathCells[neighbourValue].yRotation, 0f, Space.Self);
Instantiate(Waypoint, new Vector3(pathPoint.x, 0.75f, pathPoint.y), Quaternion.identity);
}
}
I create an random Path with Tiles AND with waypoints on this path.
This works fine.
Then I create an waypoint array with all generated waypoints.
public GameObject[] WaypointsArray;
private void CreateWaypointPath()
{
WaypointsArray = GameObject.FindGameObjectsWithTag("Waypoint");
}
Everything is fine. I can see the waypoint array in the editor and the included waypoints gameobjects.
Then there is spawning an enemy who should follow the waypoints in the waypoint array.
But here is my problem
private GridManager gridManager;
private GameObject waypoint;
void Start()
{
waypoint = gridManager.WaypointsArray[0];
}
In this line he says: “Object reference not set to an instance of an object”
What do I wrong?