Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJosh Campbell
4,463 PointsThe name 'NavMeshAgent' does not exist in the current context
I've followed the directions in the video twice now and I still cannot figure out what the issue is. My bird game object has a NavMeshAgent component and I've followed the directions to bake the Nav Mesh in the environment object, but when I go to write the code and declare my NavMeshAgent variable, I get the above message. I've done everything I can think of and my code matches that in the example exactly, but I still get the same issue.
Sean Hernandez
Courses Plus Student 9,350 PointsThanks Josh this answer was spot on. Much appreciated!!
4 Answers
Daniel Coelho
8,329 PointsAlso had this problem, you fixed it for me. Thanks!
Jon Kealy
9,082 PointsAn easier solution would be to right click on "NavMeshAgent" highlighted in red and hover over resolve. This brings up the option to add UnityEngine.AI. Select it and the screen will refresh and 'using UnityEngine.AI' will appear near the top.
Chase Grijalva
255 PointsI had this problem too and found the very same solution.
Patrick Bowles
14,993 PointsI found that adding "using UnityEngine.AI;" at the top of the script file also works.
Josh Campbell
4,463 PointsJosh Campbell
4,463 PointsI actually ended up figuring this out, so I thought I'd leave this comment for anyone else who runs into the problem. I closed Unity/MonoDevelop and re-opened them and when I did, private NavMeshAgent had been changed to private UnityEngine.AI.NavMeshAgent. So, to fix the problem just add the using UnityEngine.AI namespace and all should be well.