I have found that I can add a NavMeshSurface to my scene. Great!
However, I cannot reference a NavMeshSurface component in my script. Not so great.
If I go to Edit Script on the component, it brings me to NavMeshSurface.cs I can see that it is in the Unity.AI.Navigation namespace. However, if I add a using statement for this namespace I am told that Navigation does not exist in the UnityEngine.AI namespace. Is this a bug?
You should definitely be using the package from the package manager.
It looks like your script cannot find the UnityEngine.AI.Navigation. Where do you keep your script? Is there any assembly definition (.asmdef) file in the same folder hierarchy?
Does the code compile correctly? Or does it throw errors in the console, or is it just that your IDE (Visual Studio, Rider, …) doesn’t recognise it? Btw. which version of Unity are you using?
If I declare a NavMeshSurface object in Visual Studio, it gets a red squiggle. If I save the file it fails to compile in Unity and says the type of namespace name ‘NavMeshSurface’ could not be found.
Make sure that to use only ai navigation from the package and your project doesn’t contain anything from the NavMeshComponents GitHub repository. If the issue still persists, you can share your project with me in a private message so I can take a look.
Ok.I figured it out while making a simple project to replicate the issue.
I was following a tutorial (which used the github repo) which used:
using UnityEngine.AI
When I checked the namespace of the NavMeshSurface class, my brain blanked that UnityEngine changed to Unity and I tried to use:
using UnityEngine.AI.Navigation
I SHOULD have used:
using Unity.AI.Navigation
Which is dumb, because, as I looked back at my post, I can see that is what I called out. However, that was not what I put in the code Adding the CORRECT namespace solves the problem.
I apologize for taking up your time and feel foolish.
Thank you very much!
I would love to know the answer too. I searched docs and everywhere to find the namespace and eventually found here the solution. Makes absolutely no sense.