Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

2D NavMesh Plus - Components and Extensions System

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

  1. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    Hi All,

    Introducing to public (Unofficial) 2d NavMeshComponents for Unity.

    2D NavMesh Plus

    NavMesh Plus [Git] - This repository is fork of [Unity NavMeshComponents] enhanced with Extensions system for 2d Pathfinding and more.

    Features:
    • Implements source collector of tiles, sprites and 2d colliders
    • Supports both mesh and collider sources
    • Rectangular, hexagonal and isometric tilemaps
    • Runtime bake optimizations
    References:
    NavMesh Plus - [Demo] [Samples]
    NavMeshComponents - [Git]
    Documentation and samples - [Wiki]
    Additional links - [Old Thread]

    This thread is dedication for help and collaboration on topic.

     
    Last edited: May 30, 2022
  2. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    Components & Extensions:
    • NavMeshLink
    • NavMeshModifier
    • NavMeshModifierVolume
    • NavMeshSurface:
      • NavMeshCollectSources2d
      • NavMeshCollectRootSources2d
      • NavMeshCacheSources2d
    Utilities
    • NavMeshExtensionsProvider.cs
    • NavMeshBuilder2d.cs
    • NavMeshExtension.cs
      • NavMeshBuilderState.cs
     
    Last edited: May 30, 2022
  3. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    FAQ:
    Q: How to change NavMesh padding?
    A: Navmesh draws where the center of the Agent can reach, not his edge. Reduce Agent's radius to get navmesh closer to the edge. Bake again to see results.

    Q: How can I connect two NavMeshes together or point to the agent that there is a "jump" between?
    A: With NavMeshLinks you can connect NavMeshes or place triggers for certain actions like: jump, open a door.

    Q: Can I make a passage that is blocked to be walkable after certain action?
    A: Yes, you can update mesh at runtime, or use NavMeshObstacle
     
    Last edited: May 31, 2022
  4. julesx

    julesx

    Joined:
    Jan 19, 2022
    Posts:
    2
    upload_2022-5-21_21-47-48.png

    How can I increase the amount of space the NavMesh generates on my path? Ideally I'd like it to more closely stick to the sides of the road. I am using Isometric 2D tilemap.
     
  5. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    Hello @julesx

    Thank you for feed back. This question is poping more times that I'm expected, here is references with details and explanations https://github.com/h8man/NavMeshPlus/issues/67

    Share your thoughts on how we can improve documentation to avoid this situation again.
     
    Last edited: May 22, 2022
  6. julesx

    julesx

    Joined:
    Jan 19, 2022
    Posts:
    2
    the link provided https://docs.unity3d.com/Manual/class-NavMeshSurface.html is dead

    when I look at the settings for NavMeshSurface directly, the only setting that seems to apply is "Override Tile Size" - changing it doesn't seem to have any effect on the baked mesh. Trying both 1 and 1000 makes no difference.

    i don't understand how smooth cornering or the nav mesh static methods relate to the baked walkable area being smaller than the visual path
     
  7. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
  8. Aryazaky

    Aryazaky

    Joined:
    Apr 20, 2020
    Posts:
    1
    Hello! First of all, thank you so much for making this! You're a real lifesaver. I'm here to ask, is there a feature to merge 2 NavMeshes if they overlap on top of each other, has the same default area, geometry source, and same layers included?
    upload_2022-5-30_13-21-48.png
    I'm planning to use this on a very big map, that's why I planned for each Monster to have their own NavMeshSurface, limited by volume.
     
  9. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    Hello @Aryazaky,

    You cannot just stitch together two navmeshes, but you can:
    1) inter connect navmesh with a link. https://docs.unity3d.com/ru/2019.4/Manual/class-NavMeshLink.html
    2) runtime bake area that is currently loaded

    The sample scenes with links and runtime bake are here:
    - 4_sliding_window_infinite.unity
    - 7b_dungeon_tile_prefabs.unity
    https://github.com/Unity-Technologies/NavMeshComponents/tree/master/Assets/Examples/Scenes

    Samples specific to NevMeshPlus are here https://github.com/h8man/RedHotSweetPepper
     
  10. Boogiew

    Boogiew

    Joined:
    Mar 23, 2022
    Posts:
    12
    Hi @vhman
    Right now I'm having a problem I can't find the cause of.
    When I instantiate a gameobject sometimes it gets instantiated with its x rotation set at -90, I'm just wondering if anybody else has had this problem or if it's even possible your extension can be the source of this problem.

    I have my NavMesh2D which is also rotated -90 on X, but it is not a child and it has no children, so from my pov it's not causing it, it's just odd that my problem is also -90 on X.
     
  11. shuhungchu

    shuhungchu

    Joined:
    Mar 30, 2022
    Posts:
    2
    Hi @vhman
    first, thx you for make NavMeshPlus.

    When I use NavMeshPlus in Unity 2021.1.21f1
    And follow your start SOP.
    But When I click the bake , nothing happened.....
    I try to using in Unity 2021.3.1f1 , it's working!

    do you know why i can't use NavMeshPlus in Unity 2021.1.21f1?
    and how to fix it?
     
  12. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    @shuhungchu

    I found that if NavMeshCollectSource2d added first and NavMeshSurface after - it will not work and no error displayed. I planning to improve setup experience, but I always don't have spare time to do it.

    So add NavMeshSurface first and NavMeshCollectSource2d after. Enable components Debug view and verify that NavMeshCollectSource2d has NavMeshOwner.
    upload_2022-6-29_17-13-19.png
     
  13. shuhungchu

    shuhungchu

    Joined:
    Mar 30, 2022
    Posts:
    2
    @vhman Thank you ,Man!
    I enable the debug view and check NavMeshCollectSource2d has NavMeshOwner.
    It's work!!!

    Very Very Thank You!
     
    vhman likes this.
  14. infinitudegame

    infinitudegame

    Joined:
    Jul 2, 2015
    Posts:
    13
    Hi @vhman
    first, thx you for make NavMeshPlus.

    i found that move agent vertical would be jittery.however other direction move has no such problem.
    i used unity2021.3.4f1.

    how to fix this?

    thank you
     
  15. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
  16. infinitudegame

    infinitudegame

    Joined:
    Jul 2, 2015
    Posts:
    13
    Hi @vhman
    Thank you very much!
    I have read the known-issues.But here is a weird thing happen.
    I setup a new test project, that i didn't ajust x. the agent will get stuck while moving on Y axes in editor mode.However i build and run the agent were moving smooth on Y axes.That's incredible!
    I have attached the project here!You can check it!
     

    Attached Files:

    MikeSemicolonD and vhman like this.
  17. OldRod

    OldRod

    Joined:
    Mar 2, 2009
    Posts:
    136
    This asset looks great! Thank you so much for sharing it! Would this work with a 2D builder/RTS game where objects are added to, and sometimes removed from, the scene over time? Does it update the navmesh as obstacles are added/removed?
     
  18. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
  19. nwstory

    nwstory

    Joined:
    Dec 8, 2020
    Posts:
    3
    Hey, this is an awesome asset!

    I have a question for an issue I cant quite figure out, can this generate a navmesh that spans multiple tilemaps?
    At the moment, I can only make a navmesh for each tilemap. Was just wondering if Im doing something wrong ^.^ haha
     
  20. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
  21. nwstory

    nwstory

    Joined:
    Dec 8, 2020
    Posts:
    3
    @vhman Hey, thanks for the quick reply!

    So I think the issue is that the tilemaps are in different places in the hierarchy under different grid components, Only the first one in the hierarchy is used to create the navmesh? I had this set up as I use a chunk loading system so I had a seperate Grid component + tilemap for each 'Chunk'.

    I've actually changed my approach to this. Since the Tilemaps im using to generate the navmesh are invisible and actually only used to bake the navmesh before runtime, ive just combined the tilemaps together since they dont need to load in and out with the chunks - I can remove them from the project entirely when I have a complete navmesh.

    So issue solved (I think lol) just thought id provide details on what my issue was.

    Thanks for your help and this awesome tool!
     
  22. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    @nwstory

    That issue was in old navmeshplus design. New navmeshplus components and extensions doesn't have such limitation. Also there is ability to set root objects explicitly.
     
  23. nwstory

    nwstory

    Joined:
    Dec 8, 2020
    Posts:
    3
    @vhman Good to know for future projects, cheers :)
     
  24. Vulpeculus

    Vulpeculus

    Joined:
    Oct 19, 2019
    Posts:
    5
    I'm using navmeshplus for its ability to use navigation agents with tilesets.
    Thanks a lot for that !
    I think there is an issue with pathstatus, I can't get it to work when using navmeshplus.
    It looks like it's working with 3D, but I can' t get it to work on 2D with tilesets, it always returns true, whatever I do (even when no path has been calculated nor set?).
    Is this a known issue, and is there a workaround, or I am doing something wrong ?
     
  25. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    Hello @Vulpeculus

    NavMeshPlus does baking, and not involved after, navmesh is Unity native system. I believe there some other issue in your code.
     
  26. Vulpeculus

    Vulpeculus

    Joined:
    Oct 19, 2019
    Posts:
    5
    @vhman

    You were right, after cross-testing I can get it to work with code, but not with visual scripting although using the exact same algorythm.
    Probably not using the right nodes. Thanks and sorry ! :)
     
  27. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    AI Jittering/Not moving

    Hello All,

    As this issue popped countless time, I'm glad to say that community found a workaround https://github.com/h8man/NavMeshPlus/issues/90

    I would glad to hear a feed back if it doesn't work for You.
     
  28. mizak

    mizak

    Joined:
    Jun 5, 2014
    Posts:
    14
    @vhman

    Hey vhman, I have an issue I'm hoping you can help me with. I'm attempting to bake 2 tilemaps at runtime with the NavMeshSurface. It only seems to generate the navmesh for tiles that are set in editor mode and not for tiles that are set during runtime. The bounds are set correctly, and the number of sources looks correct as well. Perhaps the sources values are not correct.

    My sprites for the first tilemap are set to collider type none and the 2nd tilemap (walls) are set to Sprite to work with the composite collider and tilemap collider 2d.

    My initial settings are from your runtime demo in the Pepper project. The modifiers are on each of the two tilemaps and the runtime bake script is on the grid GO. The navmesh itself has the navmeshsurface, collectsources2d, collectrootsources2d, and cachesources2d with override by grid enabled for the collect sources and the root set to the grid GO.

    In the following image the brown section in the bottom left was set in the editor mode for the tilemaps and the upper right is the corner of my runtime generated tilemaps. For some reason even though the sources count is > 8000 (64x64 grid) it only bakes the brown section (gray is walls with a composite collider and tilemap collider 2d).
    upload_2022-9-26_9-58-20.png
    Tilemap 1:
    upload_2022-9-26_9-59-26.png
    Tilemap 2:
    upload_2022-9-26_10-0-0.png

    Thanks for your time!
     
  29. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    @mizak

    upload_2022-9-26_18-22-26.png

    That is what I understand from the post. And that is what I see o the scene.

    1) World bound filled with Walkable mesh (check)
    2) Tilemap 1 is default - Walkable. (check)
    3) Tilemap 2 is override - Non walkable (check)

    Can you describe expected result (with images)? I will try to explain the setup your need.
     
  30. mizak

    mizak

    Joined:
    Jun 5, 2014
    Posts:
    14
    Hey thanks for the quick response. I took a bigger screenshot to show the full tilemap.

    The two tilemaps are layered on top of each other.
    The gray areas are tilemap 2 which is override - non walkalble.
    The other tiles (grass, sand, water, etc) are tilemap 1 which is default - walkable.

    The navmesh does not generate at all without hand placed tiles, though the bounds get correctly set as center 32,32 with 32,32 extents and the sources count is > 8000.

    The bottom left area is hand placed tiles for both tilemaps just for testing this, the brown is tile map 1 and the gray is tile map 2. Once there are some hand placed tiles the navmesh generates somewhat though it ignores the runtime set tiles of the 64x64 grid.
    upload_2022-9-26_11-55-26.png

    So I need the runtime functions BuildNavMesh() and UpdateNavMesh() to take into account the tiles I set in runtime.
     
  31. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    @mizak

    Here is my quick math: 64x64 = 4к
    Why you have 8k? Remove 1st map and bake 2nd, or vice versa. Number of sources should be less than 4k.
    It can be that tile map is populated with "invisible" tiles, so it naturally flood all area as non-walkable.

    Try to troubleshoot for a while. As last resort - send a test project.
     
  32. mizak

    mizak

    Joined:
    Jun 5, 2014
    Posts:
    14
    @vhman

    That helped me figure a lot out. The 8k was from the two 64x64 tilemaps together. There are empty tiles in tilemap2 where the walls are NOT present so that was causing the override - non walkable to overlap the walkable from tilemap1. I'm going to refactor to set those tiles to null instead of an empty png and see if that works for layering the two tilemaps.

    Currently the navmesh looks like this because there is no override non walkable yet but I think i've got it figured out.
    upload_2022-9-26_12-52-1.png

    Thanks again, you were super helpful!!

    Update:
    Re-added Modifier to Tilemap 1 - Default Settings.
    Changed Modifier on Tilemap 2 - Non Walkable override.

    However on my tilemap generation I set empty Tilemap 2 tiles to null instead of an empty png and it generated the NavMesh how I wanted:
    upload_2022-9-26_13-52-48.png
     
    Last edited: Sep 26, 2022
    vhman likes this.
  33. mizak

    mizak

    Joined:
    Jun 5, 2014
    Posts:
    14
    Hey @vhman,

    I got my navmesh working quite well since my last post with your help. Now I'm in the process of updating to Unity's Entities 1.0 and Editor 2022.2.0b9 which comes with a lot of errors and issues.

    It seems to be breaking NavMeshPlus slightly. From what I can see in the debug mode of the editor the Nav Mesh Owner field is not being set for the collect sources scripts. I haven't tried tinkering with it much yet though I will tonight or tomorrow, but I thought it might be something you'd want to be aware of (or already are). Not certain if it's on my end, your end, or Unity's.

    Here's an image of the error and debug mode scripts:
    upload_2022-9-29_18-33-54.png

    Thanks!
     
  34. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    @mizak,

    All error seems to be inside NavMeshPlus, remove Extensions components and add them again
     
  35. mizak

    mizak

    Joined:
    Jun 5, 2014
    Posts:
    14
    Tried that a couple times, re-adding all components in order of NavMeshSurface -> CollectSources2d -> CollectRootSources2d -> CacheSources2d. Still null owner reference. I tried re-adding the whole NavMeshPlus project fresh from git in case the update process changed some references but the same thing happens.

    I'll try to figure out the cause, I imagine some change in the updates broke the way NavMeshPlus adds that owner field. I'm just busy trying to refactor my whole project lol, pretty much everything changed in that 1.0 experimental release.

    Thanks again!
     
  36. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    @mizak,

    I didn't tested 2022.2.0b9. I will check on weekend.
     
    mizak likes this.
  37. mizak

    mizak

    Joined:
    Jun 5, 2014
    Posts:
    14
    @vhman The issue was with the new update I had the package com.unity.ai.navigation which holds NavMeshSurface. So when NavMeshSurfaceOwner in NavMeshComponents looked for a UnityEngine.AI.NavMeshSurface it failed. What was there was instead a Unity.AI.Navigation.NavMeshSurface.

    I fixed it by manually dragging the NavMeshSurface from NavMeshPlus/NavMeshComponents on to my GameObject to replace the Unity.AI.Navigation.NavMeshSurface. However I am now failing to collect sources. Gonna have to figure that out now.

    Update: Inability to gather sources was the same issue, the Modifier was replaced by the modifier from Unity.AI.Navigation.NavMeshModifer. So I manually dragged the NavMeshPlus/NavMeshComponents NavMeshModifer onto my source object and it worked.

    -Mizak
     
    Last edited: Oct 7, 2022
  38. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    @mizak, So there is new Unity package Unity.AI.Navigation with NavMeshSurface? can it be removed? or it's a part of API now?
     
  39. APTEM59

    APTEM59

    Joined:
    Dec 27, 2019
    Posts:
    27
    Is there any way to use composite collider attached to tilemap collider with nav mesh? Composite collider (which i need for Shadow Caster 2D Tile Map script) requires rigidbody2d which forces mesh baking to ignore the tilemap obstacle:
    upload_2022-10-8_16-37-58.png
     
  40. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
  41. APTEM59

    APTEM59

    Joined:
    Dec 27, 2019
    Posts:
    27
  42. mizak

    mizak

    Joined:
    Jun 5, 2014
    Posts:
    14
    It is a pre-release package that can be removed. Not sure when I installed it, possibly when updating all the experimental entities packages.
     
  43. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,761
    Try using the CompositeCollider2D in Polygon mode to see if it works then.
     
  44. APTEM59

    APTEM59

    Joined:
    Dec 27, 2019
    Posts:
    27
    Unfortunately, still doesn't work
     
  45. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,761
    No idea then.

    To note here, when you don't add a Rigidbody2D, you still get a hidden Static body. It's just a convnience thing not adding it; it makes no difference to the Collider2D.CreateMesh produced which is what this NavMesh feature uses.
     
  46. APTEM59

    APTEM59

    Joined:
    Dec 27, 2019
    Posts:
    27

    Ok, so the solution was extremely easy, i just removed and created tilemap again, and now everything's fine. Anyway, thanks for help.
     
    vhman likes this.
  47. DavidNLN

    DavidNLN

    Joined:
    Sep 27, 2018
    Posts:
    90
    Same issue here at 2022.2.0b1 - This package comes auto installed as far as I see, I removed it and it solved my issue, but it would be nice if we can add it back later. can you resolve the conflicts?
     
  48. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    Yes, it's just a naming conflict. It can be resolved.
     
  49. DavidNLN

    DavidNLN

    Joined:
    Sep 27, 2018
    Posts:
    90
    Hi I got this issue where the generated navmash is not tight enough, for some reason the polygon generated around the navmeshModifier is much bigger than the collider, which means that the agent cant pass in places they should be able to

    upload_2022-10-12_13-46-59.png
     
  50. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    374
    @DavidNLN

    Is this your case?

    Q: How to change NavMesh padding?
    A: Navmesh draws where the center of the Agent can reach, not his edge. Reduce Agent's radius to get navmesh closer to the edge. Bake again to see results.

    Also, there Advance settings in navmesh with which you may want to play around.