Search Unity

2D NavMesh Plus - Components and Extensions System

Discussion in '2D' started by vhman, May 11, 2022.

  1. HazeQuo

    HazeQuo

    Joined:
    Jul 19, 2018
    Posts:
    1
    Hello everyone!

    I seem to be having an issue with inverting the navmesh.
    I am trying to utilise the "maze" approach, but so far I can't seem to make it happen.

    Here is something I'am trying to achieve:

    upload_2022-11-12_20-24-16.png

    Now, basically player should be able to move along the black paths to reach the blue dots whenever I click them.
    I have managed to achieve that another way around, which looks like this:

    upload_2022-11-12_20-25-38.png

    I set the paths (black lines) to non-walkable.
    I've set the background to walkable.
    At this point the NavMesh gets baked just fine.

    Hovewer I am trying to invert the process. So I set the black lines to walkable and background to non walkable. I've also decreased agent size, height and slope just in case that stood in the way, but NavMesh does not seem to be generated at this point.

    Here is how my current approach looks like:

    upload_2022-11-12_20-29-57.png
    upload_2022-11-12_20-30-14.png
    upload_2022-11-12_20-31-7.png


    Am I getting confused somewhere along the way?
    The github repo wiki mentioned something about grid/tiles. However the project I am currently working on does not utilise grids/tilemaps, and the original approach with base floor being walkable seems to work fine with just sprites.

    Does anyone know a solution to this issue?

    Regards,
    Kamil.
     
  2. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    Hello @HazeQuo,

    1. Sprites are supported, no need for grid or tilemap (wiki just show one case)
    2. It is possible to bake a maze

    What you can try:
    1. BG - remove modifier, Default - non-Walkable, Path - walkable
    2. BG - non-walkable, Default - walkable, Path - walkable

    Also check logs to see calculated world bound

    Height for agent can be any, 1 unit is fine. Slope 45 and Step 0.2 also fine. The only issue I can see is path is too narrow, so you need to play with settings more.

    Or send small project with issue reproduced
     
    MarekUnity likes this.
  3. cherub8128

    cherub8128

    Joined:
    Sep 1, 2022
    Posts:
    4
    Please help.
    Unity Version: 2022.2.0b15 beta
    When added together with AI Navigation 1.1.1, the following 36 error messages appear.

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshSurfaceEditor2d.cs(12,26): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshCacheSources2dEditor.cs(8,26): error CS0246: The type or namespace name 'NavMeshCacheSources2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshAssetManager2d.cs(30,46): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshAssetManager2d.cs(65,40): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshAssetManager2d.cs(74,45): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshCollectRootSources2dEditor.cs(8,26): error CS0246: The type or namespace name 'NavMeshCollectRootSources2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshAssetManager2d.cs(93,27): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshCollectSources2dEditor.cs(8,26): error CS0246: The type or namespace name 'NavMeshCollectSources2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshSurfaceEditor2d.cs(356,44): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshAssetManager2d.cs(131,47): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshSurfaceEditor2d.cs(362,47): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshAssetManager2d.cs(167,37): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshSurfaceEditor2d.cs(370,36): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshAssetManager2d.cs(190,36): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshAssetManager2d.cs(198,41): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshAssetManager2d.cs(228,47): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshAssetManager2d.cs(251,49): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshAssetManager2d.cs(14,20): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)

    Library\PackageCache\com.h8man.2d.navmeshplus@4a5aec0a09\NavMeshComponents\Editor\NavMeshAssetManager2d.cs(24,20): error CS0246: The type or namespace name 'NavMeshSurface2d' could not be found (are you missing a using directive or an assembly reference?)
     
    Last edited: Nov 17, 2022
  4. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    @cherub8128 Hello,

    Why do you need AI Navigation 1.1.1 in the first place? I working on reworking naming to resolve conflict. But I'm in lack of time

    But still, you don't need AI Navigation 1.1.1 for 2d.
     
  5. cherub8128

    cherub8128

    Joined:
    Sep 1, 2022
    Posts:
    4
    In 2022.2 beta, There is no UnityEngine.AI Namespace and Navmesh Component. Therefore, AI Navigation 1.1.1 must be installed.
    I fixed this issue by downgrading to the 2021.3 LTS version.
     
    vhman likes this.
  6. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    Didn't tested with 2022.2 beta, I will check.
     
  7. MrPapayaMan

    MrPapayaMan

    Joined:
    Feb 16, 2021
    Posts:
    42
    I seem to struggle with some of the functionality I use with the normal navmesh such as Navmesh.SamplePosition and Navmesh.Raycast.

    Do these work on with this?

    Code (CSharp):
    1.     private void Update()
    2.     {
    3.         bool blocked = NavMesh.Raycast(T.position, Target.position, out hit, NavMesh.AllAreas);
    4.         Debug.DrawLine(T.position, Target.position, blocked ? Color.red : Color.green);
    5.  
    6.         if (blocked)
    7.             Debug.DrawRay(hit.position, Vector3.up, Color.red);
    8.     }
    Example:




    Should turn red on hit.
     
  8. lan_tern

    lan_tern

    Joined:
    Aug 24, 2019
    Posts:
    2
    hey can you help me

    i follow your tutorial and i hit a problem
    when i click bake in navmeshsurface
    it didn't show in scene
     

    Attached Files:

  9. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    @MrPapayaMan

    Green line goes through nav mesh, cause you can sample position on navmesh, these is a hit.
    Raycast will show no hit on edges and area painted red.

    upload_2022-12-1_13-55-42.png
     
  10. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
  11. lan_tern

    lan_tern

    Joined:
    Aug 24, 2019
    Posts:
    2
    still not showing up in the scene

    Screenshot (42).png

    when i remove wall tilemap it appears but not full Screenshot (44).png
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Did you see the warning? Maybe that's important.
     
  13. MrPapayaMan

    MrPapayaMan

    Joined:
    Feb 16, 2021
    Posts:
    42
    Thanks for the response.

    I'm pretty sure its not registering unless my setup is completely off.





    It is always green.

    I just copied the code from the docs.

    Code (CSharp):
    1. // TargetReachable
    2. using UnityEngine;
    3. using UnityEngine.AI;
    4.  
    5. public class TargetReachable : MonoBehaviour
    6. {
    7.     public Transform target;
    8.     private NavMeshHit hit;
    9.     private bool blocked = false;
    10.  
    11.     void Update()
    12.     {
    13.         blocked = NavMesh.Raycast(transform.position, target.position, out hit, NavMesh.AllAreas);
    14.         Debug.DrawLine(transform.position, target.position, blocked ? Color.red : Color.green);
    15.  
    16.         if (blocked)
    17.             Debug.DrawRay(hit.position, Vector3.up, Color.red);
    18.     }
    19. }
    I built the navmesh through the NavmeshSurface2d and not through the navigation tab.

    Would appreciate it if you had any more suggestions.
     
  14. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    @MrPapayaMan,

    I'm 100% sure that it is not a NavmeshPlus problem, as it produces Unity "native" navmesh surface.
    I also checked my test projects and found that I used NavMesh.Raycast before
    Code (CSharp):
    1.             NavMeshQueryFilter filter = new NavMeshQueryFilter()
    2.             { agentTypeID = Agent.agentTypeID, areaMask = Agent.areaMask };
    3.                 if (NavMesh.Raycast(path[i], path[i + 1], out hit, filter))
    4.                 {
    5.                     //blablalba
    6.                 }
    But, form page you get a code Trace a line between two points on the NavMesh. and If the ray hits a NavMesh boundary, the function returns true and the hit data is filled - I assume it works not as physics and colliders.

    The source and destination points are first mapped on the NavMesh, then a ray is traced from the source point towards the target. - Also it's not clear if projection is done or you need to feed point on a surface.

    So, you just need to play around to get filling on how it works.
     
  15. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    Last edited: Dec 1, 2022
  16. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    @MelvMay

    The warring is fine, I see "good" rotation to -89.99.

    It is related to long standing issue that agents don't move straight up, some kind of bug in Unity.
    And workaround is to tilt mesh slightly so we always have movement with an angle
    https://github.com/h8man/NavMeshPlus/issues/90
     
    MelvMay likes this.
  17. MrPapayaMan

    MrPapayaMan

    Joined:
    Feb 16, 2021
    Posts:
    42
    @vhman Thank you for the assistance :)
     
  18. Zecrah

    Zecrah

    Joined:
    Nov 1, 2016
    Posts:
    7
    Hi, any plans for 2022.2 support now it is tech stream? Thanks! :)
     
    vhman likes this.
  19. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    Yes, I will update to 2022 and further support. It just I cannot find time to work on that.

    UPDATE.
    Just remove AI Navigation package and NavMeshPlus starts to work in 2022. Just a name collision. But why it installed by default on update? It's a good question.

    I will change naming, I suppose.
     
    Last edited: Dec 26, 2022
  20. DavidNLN

    DavidNLN

    Joined:
    Sep 27, 2018
    Posts:
    90
    @vhman after updating to the latest version I get this error when running the package

    upload_2022-12-29_22-16-13.png
    It seems to be happening only in debug mode, any idea?
     
  21. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    @DavidNLN Got it. I'll look on that. Do you have steps to reproduce?

    Is it fixed if component removed and added back?
     
  22. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    * breaking changes, name-space changed, remove obsolete surface 2d

    Those changes are required to work with unity 2022, it defiantly will break your current project.

    Sorry for bad timing.

    Regards,
     
  23. Wokarol

    Wokarol

    Joined:
    Aug 1, 2017
    Posts:
    34
    Hey, @vhman. I tried to install the package today as I need 2D navigation for my project.
    No matter what I try I get flooded with errors tho.

    First I tried to install just the repo (as a package) and got those errors:
    upload_2023-1-11_17-37-11.png

    Then I tried to install the AI Navigation package. That obviously resulted in even more errors:
    upload_2023-1-11_17-40-9.png

    When copy pasted into the Asset folder, it compiles correctly.
     
  24. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    Hi. @Wokarol

    I don't have answer. But I will check it.

    UPDATE:

    I confirm this issue.
     
    Last edited: Jan 12, 2023
  25. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    @Wokarol

    I changed ALL guids and names. Should work for you and break for everyone who already using.
     
  26. Wokarol

    Wokarol

    Joined:
    Aug 1, 2017
    Posts:
    34
    Thanks, when I imported it in as a package (in a test project for now), it worked perfectly fine.
    But it of course broke all the component references which might be painful to fix in anything bigger than a test project. Is the GUID change needed for sure?
    The original issue (when you import only your repo and not the unity package) seems to be something different than the GUID collision.
     
  27. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    Yes, I saw that 0 files were in a package. Only after I changed guids it start working.

    I know how painful it is, but I made a mistake, and more I was waiting - more troubles will be in the future.

    Also I want to mention tools used https://github.com/jeffjadulco/unity-guid-regenerator - great package.
     
  28. Darenth

    Darenth

    Joined:
    Jan 25, 2020
    Posts:
    4
    Hello @vhman, thanks for your efforts to fit your package into the new reality. I have the same problem like @Wokarol:
    upload_2023-1-14_11-19-30.png
    Is it possible to use your package with unity 2022.2 and navigation ai package?
    Thanks in advance
     
  29. Wokarol

    Wokarol

    Joined:
    Aug 1, 2017
    Posts:
    34
    Wait, I just realised something. Won't that make your package incompatible with Unity's samples?
     
  30. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    @Darenth,

    I tested package with Unity 2022.2.1f1 - I imported into empty project and had no issue

    @Wokarol

    What exact samples? Form Navigation Components github repo? Just change namespace and it will be fine. Also that repo in not maintained as there new package form Unity
     
    Darenth likes this.
  31. Darenth

    Darenth

    Joined:
    Jan 25, 2020
    Posts:
    4
    @vhman , thanks for your fast response. Yes, you are right, there are no conflicts anymore.
    I have 2 questions, why did you remove surface2d element? What I can replace it? Unfortunately, I cannot do the same with simple surface :/ I dont understand why. I performed exactly as you described:
    1. Copy repo into your Asset folder (or install as a package).
    2. Create Empty Object in scene root.
    3. Add NavMeshSurface component to Empty Object and add NavMeshCollecSources2d component after.
    4. Click Rotate Surface to XY (to face surface toward standard 2d camera x-90;y0;z0)
    5. Add NavMeshModifier component to scene objects obstacles, override the area.
    6. In NavMeshSurface hit Bake.
    and what I see it's only two icons in one place, any bake territory.
    Could you suggest what I could do wrong?
    upload_2023-1-14_17-33-55.png
     
  32. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    @Darenth

    1) why did you remove surface2d element? - I'm not able to maintain thousands lines of Unity API, as in every version there is new API, deprecated API or braking changes in it. I'm tired of it.

    2)What I can replace it? - the confusion is from Navigation AI package, remove it, or just remember that NavMeshPlus have "Navigation" Prefix in contrast to "NavMesh".

    1. Copy repo into your Asset folder (or install as a package).
    2. Create Empty Object in scene root.
    3. Add "Navigation Surface" component to Empty Object and add NavMeshCollecSources2d component after.
    4. Click Rotate Surface to XY (to face surface toward standard 2d camera x-90;y0;z0)
    5. Add "Navigation Modifier" component to scene objects obstacles, override the area.
    6. In "Navigation Surface" hit Bake.
    Also, I doing all changes in this project https://github.com/h8man/RedHotSweetPepper - than merge to package, so there is guarantee of working samples
     
    Darenth likes this.
  33. Wokarol

    Wokarol

    Joined:
    Aug 1, 2017
    Posts:
    34
    @vhman
    Sorry to bother you again but I tried to build the project with the package installed and I'm meet with an absolute wall of compilation errors (it works fine in editor)

    upload_2023-1-16_12-24-21.png

    On the previous project that uses the code from the repo and not the package, the same issues exists. I tried to look into it but it all looks okay, so I have no clue why it would not build.
     
  34. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
  35. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
  36. DaRk-_-HaUnT

    DaRk-_-HaUnT

    Joined:
    Jul 6, 2021
    Posts:
    1
    @vhman, hello, and thank you for your work!

    But i have a question: is it possible to update existing NavMeshSurface by loading other scene in Additive mode and update surface including added meshes?

    Because it seems, if add even empty scene, and then rebake surface , then i get 0 sources in logs

    This is surface before adding new scene and rebaked correctly:

    upload_2023-1-17_22-19-18.png

    And this is after adding an emply scene:

    upload_2023-1-17_22-20-44.png

    Have i missed something? Thank you!
     
  37. Wokarol

    Wokarol

    Joined:
    Aug 1, 2017
    Posts:
    34
    Thanks, I've tested it and it in fact works and builds properly.
    This will make development so much easier!

    One minor detail is that for some reason, the scripts from the package don't have custom icons, not sure why that would be a thing. This could also be Unity's package manager being weird.
    Either way, it works great and my actors pathfind as they should!
     
    vhman likes this.
  38. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    @Wokarol I need new icons to make it pop, as Navifation.AI gives me troubles

    @DaRk-_-HaUnT NabMeshPlus supports multiple scenes. There can be few issues, like bake was called before scene loaded, before components initialized or something similar.

    If there is a bug, I will fix it and add sample to my demo proj https://github.com/h8man/RedHotSweetPepper
     
  39. Darenth

    Darenth

    Joined:
    Jan 25, 2020
    Posts:
    4
    @vhman Thanks for your answers. I understand of course your decision.
    And great Thanks for your time and efforts!
     
  40. AllureSoul

    AllureSoul

    Joined:
    Jul 21, 2020
    Posts:
    1
    Hello, i'm having trouble with the NavMeshCollectSources2D not detecting the NavMeshSurface as NavMeshOwner. I've tried adding the surface component first and the collect sources2d component first, but it just doesn't seem to detect despite everything i try. Could anyone help? Thank you
     
  41. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    @AllureSoul I'm not so fast on updates

    Remove Navifation.Ai package.
    and follow this:
    1. Copy repo into your Asset folder (or install as a package).
    2. Create Empty Object in scene root.
    3. Add "Navigation Surface" component to Empty Object and add NavMeshCollecSources2d component after.
    4. Click Rotate Surface to XY (to face surface toward standard 2d camera x-90;y0;z0)
    5. Add "Navigation Modifier" component to scene objects obstacles, override the area.
    6. In "Navigation Surface" hit Bake.
     
  42. Apple2854

    Apple2854

    Joined:
    Jan 31, 2022
    Posts:
    1
    Hey, vhman! I got a lot of error during the build of the game. e.g. Assets\NavMeshPlus-master\NavMeshComponents\Scripts\NavMeshSurface.cs(87,16): error CS0246: The type or namespace name 'NavMeshData' could not be found (are you missing a using directive or an assembly reference?). How do I fix this?
     
  43. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    This is discussed already in the posts above.
     
  44. Evorlor

    Evorlor

    Joined:
    May 5, 2021
    Posts:
    4
    I am using Unity's 2D tilemap. Is it possible to bake my NavMesh based on the colliders of my tiles, instead of having to have multiple tilemaps?
     
  45. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
  46. Evorlor

    Evorlor

    Joined:
    May 5, 2021
    Posts:
    4
    Thanks for your reply. The documentation and demo show multiple tilemaps, instead of one tilemap with colliders. Perhaps I am missing it?

    To clarify, I am trying to have one tilemap (hexagonal), where some of the tiles are walkable, and some are not. Instead of having the entire tilemap being walkable or not. I am also looking to change which tiles are walkable at runtime, so I will be rebaking at runtime.
     
  47. Evorlor

    Evorlor

    Joined:
    May 5, 2021
    Posts:
    4
    Nevermind. I found my mistake. Solution:
    In NavigationSurface, set UseGeometry to PhysicsColliders, and set DefaultArea to Walkable.
    Then in my NavigationModifer, override the area with NotWalkable.

    Thank you for this great addition to the Unity Navigation!
     
  48. cyberdrunkdev

    cyberdrunkdev

    Joined:
    Dec 6, 2022
    Posts:
    32
    Giving me error that 'showNavigation is obsolete: showNavigation is no longer supported and will be removed.
     
  49. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
  50. cyberdrunkdev

    cyberdrunkdev

    Joined:
    Dec 6, 2022
    Posts:
    32
    The Unity version is: 2022.2.4f1
    Tried again: It didn't give error this time but it gave me nothing:
    First i baked the flloor just like told in wiki and the debug-log said:
    Walkable bounds[ground]: Center(0.00,0.00,0.00), Extents:(0.00,0.00,0.00)

    Then i made the non walkable area just like the wiki said and it gave me nothing.
    Nothing changed, there's no baked areas etc.

    Tried to follow this tutorial
    https://github.com/h8man/NavMeshPlus/wiki/HOW-TO#nav-mesh-basics
     
    Last edited: Feb 6, 2023