Error using "FindObjectsOfType": different than "FindObjectOfType"

In PathFinder.cs, I got a red squiggly telling me that it couldn’t use foreach because there was no IEnumerator. It turns out I had a missing ‘s’ in the method, “Object” vs “Objects”!

It couldn’t loop through the list because it was only returning one object.

Took a while to catch that one :slight_smile:

9 Likes

I wish I could say that never happens to me, but I’d be lying… Sometimes Intellisense actually works against you, since the first hit is the FindObjectOfType, not the FindObjectsOfType.

3 Likes

Arg! I just had exactly the same issue… Thanks for posting the solution guys, I was scratching my head on that one, and its such a subtle but profound difference.

2 Likes

It’s actually very very very good to run into these kind of errors when you’re working through guided content (i.e. Ben’s giving you a template code to work off of, and guiding the direction of the project).
The more of these errors you see, the more you’ll associate things like “Oh, no IEnumerator… must be that I used GetComponentInChildren<> instead of GetComponentsInChildren<>” You’ll burn that pathway into your head so when you’re in deep working on a project on your own, you’ll spot that error and immediately know where to go.

5 Likes

Thanks!! I was having the exact same issue!! Saved an hour of my life!

Forever grateful!

Thank you, been trying to work that out for ages :slight_smile:

Dude, you saved my day.
I was struggling with the same red line under “waypoints” and changing the method to FindObjectsOfType() helped me to solve it.
Thanks

1 Like

thanks :slight_smile:

Oh my god I’ve spend 2 hours trying to figure out whats wrong. Then I see this thread!

Its just a missing ‘s’!
Thank you, saved my day!

Privacy & Terms