Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

The type or namespace name 'NavMeshSurface' could not be found

Discussion in 'Navigation' started by JonR79, Sep 8, 2022.

  1. JonR79

    JonR79

    Joined:
    May 13, 2018
    Posts:
    9
    Using this experimental package:
    https://docs.unity3d.com/Packages/com.unity.ai.navigation@1.0/manual/index.html

    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?

    I found forums from the past that say to use this github repo:
    https://github.com/Unity-Technologies/NavMeshComponents

    However now the repo says that the package should be used for current versions of Unity and only to use it for previous versions.

    Not sure what I'm missing. I think it's something obvious because I don't see anyone else having this problem anymore. :(

    Thanks
     
  2. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    203
    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?
     
  3. JonR79

    JonR79

    Joined:
    May 13, 2018
    Posts:
    9
    The only .asmdef files I see are in:

    projectname\Library\PackageCache\package\

    ex:
    Library\PackageCache\com.unity.ai.navigation@1.0.0-exp.4\Runtime\Unity.AI.Navigation.asmdef

    I keep my scripts in:
    projectname\Assets\Scripts
     
  4. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    203
    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?
     
  5. JonR79

    JonR79

    Joined:
    May 13, 2018
    Posts:
    9
    Using version: 2021.3.8f1

    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.
     
  6. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    203
    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.
     
  7. JonR79

    JonR79

    Joined:
    May 13, 2018
    Posts:
    9
    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!
     
    Ponzel and MarekUnity like this.
  8. Shizola

    Shizola

    Joined:
    Jun 29, 2014
    Posts:
    470
    Why is the namespace Unity.AI.Navigation and not UnityEngine.AI.Navigation like everything else?
     
  9. unity_028AE3B1F1BC5DECE8AD

    unity_028AE3B1F1BC5DECE8AD

    Joined:
    Jul 31, 2022
    Posts:
    94
    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.