Getting CS1579 error

Hi,
I am getting error
“CS1579 foreach statement cannot operate on variables of type ‘WayPoint’ because ‘WayPoint’ does not contain a public instance definition for ‘GetEnumerator’”
for the following code
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)*
    
  •    {*
    
  •        grid.Add(wayPoint.GetGridPos(), wayPoint);*
    
  •    }*
    
  • }*

I am unable to get around this. Please help.

Thanks,
Shaktimaan

1 Like

Found the fix:
Replaced
var wayPoints = FindObjectOfType();
by
var wayPoints = FindObjectsOfType();

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

Privacy & Terms