Solve this Error

Pathfinder.cs:-

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pathfinding : MonoBehaviour
{
    Dictionary<Vector2Int, Waypoint> grid = new Dictionary<Vector2Int, Waypoint>();
    // Start is called before the first frame update
    void Start()
    {
        LoadBlocks();
    }

    private void LoadBlocks()
    {
        var waypoints = FindObjectOfType<Waypoint>();
        foreach (Waypoint waypoint in waypoints) // error in "waypoints"
        {
            var gridPos = waypoint.GetGridPos();
            if (grid.ContainsKey(gridPos))
            {
                Debug.LogWarning("Overlapping Blocks");
            }
            else
            {
                grid.Add(gridPos , waypoint);
            }
            print("Loaded" + grid.Count + "Blocks");
        }
    }
}

The error says:-
ErrorInMyCode

Hi,

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? If not, do that, please. Check the spelling of the methods which you call inside the LoadBlocks method.


See also:

My Head is going to EXPLODE!!!
I figured it out,somehow.
var waypoints = FindObjectsOfType<Waypoint>(); //Does work
I had to write “…ObjectsOf…” instead of “…ObjectOf…”

I think It is common to make such stupid mistakes while learning to code.

Absolutely. Everybody makes such mistakes. The best way to learn how to avoid them is to make them and fix them yourself. :slight_smile:

1 Like

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

Privacy & Terms