Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

2D NavMesh Plus - Components and Extensions System

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

  1. cyberdrunkdev

    cyberdrunkdev

    Joined:
    Dec 6, 2022
    Posts:
    32
    Mate! It started to work while i started recording a video for you about what i was doing. Heh. I hope you check the thread later because i'm going to make a working project tomorrow and see if it works totally as wished. Thank you :)
     
  2. cyberdrunkdev

    cyberdrunkdev

    Joined:
    Dec 6, 2022
    Posts:
    32
    Now it did it again, as soon as i add the folder in my unity Assets, it informs:
    upload_2023-2-7_17-47-40.png upload_2023-2-7_17-47-40.png


    Unity version: 2022.2.4f1
     
  3. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    Got it. That is just a warning. I'll fix it in few days
     
  4. cyberdrunkdev

    cyberdrunkdev

    Joined:
    Dec 6, 2022
    Posts:
    32
    Thanks :) I'll write if anything new appears. Your effort is helping me and many people alot!
     
  5. cyberdrunkdev

    cyberdrunkdev

    Joined:
    Dec 6, 2022
    Posts:
    32
    Is there any way to get the Z-axis of the agent rotate while moving? Would love to get the sprite rotate like a wheel, but i find it impossible.:D
     
  6. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    cyberdrunkdev likes this.
  7. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    Am I missing some thing or Navigation window was moved to Navigation.AI package in
    Unity 2022.2? So Navigation.AI is required in every project?

    Right now NavMeshPlus should work Navigation.AI just fine, but it inconvenient to have duplicated components.
    Am thinking about new NavMesh Plus redesign. If anyone have a feedback how to make NvMeshPlus better please leave a comment.
     
  8. smarart

    smarart

    Joined:
    Feb 16, 2023
    Posts:
    4
    Is it possible that there's a conflict between the NavMeshPlus package and the default NavMeshComponents package in Unity 2022.2.5.

    The navmesh component shows as: "Navigation Surface", not NavMeshSurface.
    And my C# can't find either of those NavigationSurface or NavMeshSurface.
    i'm using #UnityEngine.AI;

    I'm trying to bake a mesh on runtime, but this doesnt work:

    public NavigationSurface a;
    or
    public NavMeshSurface b;



    Another question:
    I have Walls, and i would need to make the walls tinyer, but they have this one centimeter "frame or spacing" around the wall. How to make it thinner? Didn't help that i lowered the Agent's radius.

    Here's an example in the image. It leaves some kinds of spaces around the baked area:
    https://pasteboard.co/0Le2nYu9NvmM.png

     
    Last edited: Feb 22, 2023
  9. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
  10. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    Hello All,

    Quick update:
    - Fixed icons
    - Fixed memory leak (meshes not destroyed)
    - Add tooltips
     
  11. Cevia

    Cevia

    Joined:
    Jun 7, 2016
    Posts:
    3
    Is there any way to create agents that have an irregular shape? I have a unit that is significantly wider than it is tall. What I'd want is an agent type that has more clearance on the x-dimension than the y-dimension, but it appears that the "height" variable does nothing and "radius" is used for determining both. This is, oddly enough, completely different than the way Obstacle Avoidance in NavMeshAgent works, where the y-dimension is governed by the "height" variable.
     
  12. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    @Cevia

    I think there is no way to define agent shape with Unity NavMesh.AI. Take a look at A* Pathfinding, maybe there something for you.
     
    Cevia likes this.
  13. SlapstickMojo

    SlapstickMojo

    Joined:
    Aug 9, 2013
    Posts:
    1
    Ok, stupid question -- I downloaded and copied navmeshplus into my assets folder, but no matter what I do, navmeshmodifier and navmeshsurface2d never appear in my list of components.Is there something I need to hit to make it recognize the scripts?
     
  14. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
  15. Ikuti

    Ikuti

    Joined:
    Oct 24, 2016
    Posts:
    11
    Hi, great addon! (I'm a bit suprised Unity doesn't have good 2D navmesh solution out of the box though...)
    I was wondering if you plan to create extension for nav mesh obstacle for 2D carving with the sprite renderer instead of what it is currently, with 2 possible 3D shapes. It would be a godsend for any dynamic objects that move constantly or move and than stop.
    Either way, thank you for making this addon!
     
  16. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    @Ikuti

    There will be no Obstacle support, as they ignore layers. Carving will be done with navmesh update. Right now it somewhat working and will be improved, maybe I'll introduce some wrappers.

    You can already check https://github.com/h8man/RedHotSweetPepper/tree/master/Assets/Scenes/SampleSceneRuntime.meta

    You can use update every frame, every few frames, use cache or supply your sources.

    Also I need to check this stuff public bool preserveTilesOutsideBounds { get { return m_PreserveTilesOutsideBounds != 0; } set { m_PreserveTilesOutsideBounds = value ? 1 : 0; } }
     
  17. SpicyDinosaur

    SpicyDinosaur

    Joined:
    Oct 25, 2019
    Posts:
    5
    I am having problems with The package. I'm sort of feeling around blind. I originally couldn't get the nav mesh to even show up on my screen, then the programmer I'm working with was able to get it to work and I was briefly able to get it to work and now it just... doesn't.I'm trying to follow the tutorial but what I am seeing from my end is not the same, even the actions like dragging a sprite onto the gameobject and it creating the sprite renderer component isn't a thing.

    By saying it showed up I mean I could see a blue grid of sorts. The green square in the images had a border that was the white of the "floor" I have under the layout gameobject. Basically the cut out part of the navmesh.

    The only change I made between working and not working was to turn the NavMesh gameobject into a prefab. Then I carried it over to a different scene, where it didn't work. When I went back to the test scene it no longer worked. This might be because baking it altered the prefab but I didn't revert or apply any changes to the gameobject in the hierarchy either in the test scene or the scene I tried to implement the navmesh to that had other things on it.

    I've attempted to recreate the navmesh from scratch in the test scene, along with recreating that green square since it has the nav mesh obstacle component on it. But nothing makes it work.

    The Unity version I'm using is the one that the navmesh was up to date as of, namely 2021.3.8f1. I can't remember where I found that information off the top of my head, though. I think from when I downloaded the sample project. Previously, my project was a bit behind that, but there have been no issue as far as my project working otherwise so far.

    The package itself is up to date.

    I'm not familiar with using the Nav Mesh outside of this package as this is my first attempt at using the navmesh at all.

    The attached images show what my navmesh gameobject is set up like as well as the green obstacle.


     
  18. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    Hello @SpicyDinosaur
    Tutorial and documentation cannot keep up with updates(
    I would recommend to get familiar with the package with https://github.com/h8man/RedHotSweetPepper

    From screens I see that you have only 1 source marked for a navigation, but its 'Obstacle', I think you missed 'Navigation Modifier' components
     
  19. SteveKouts

    SteveKouts

    Joined:
    Aug 23, 2012
    Posts:
    79
    Package won't compile. Im using Unity 2019.2.17f

    Compile timer just keeps spinning.

    ArgumentException: Not Found
    UnityEditor.Scripting.ScriptCompilation.SemVersionRanges.GetExpression (System.String expression) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/SemVersionRanges.cs:35)
    UnityEditor.Scripting.ScriptCompilation.SemVersionRangesFactory.GetExpression (System.String expression) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/SemVersionRangesFactory.cs:16)
    UnityEditor.Scripting.ScriptCompilation.EditorCompilation.SetTargetAssemblyDefines (UnityEditor.Scripting.ScriptCompilation.EditorBuildRules+TargetAssembly targetAssembly, UnityEditor.Scripting.ScriptCompilation.SemVersionRangesFactory semVersionRangesFactory, System.Collections.Generic.Dictionary`2[TKey,TValue] assetPathVersionMetaDatas, System.String[] editorOnlyCompatibleDefines, System.String[] playerAssembliesDefines, UnityEditor.Scripting.ScriptCompilation.ScriptAssemblySettings settings) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:1953)
    UnityEditor.Scripting.ScriptCompilation.EditorCompilation.UpdateAllTargetAssemblyDefines (System.Collections.Generic.IDictionary`2[TKey,TValue] customScriptAssemblies, UnityEditor.Scripting.ScriptCompilation.EditorBuildRules+TargetAssembly[] predefinedTargetAssemblies, System.Collections.Generic.Dictionary`2[TKey,TValue] assetPathVersionMetaDatas, UnityEditor.Scripting.ScriptCompilation.ScriptAssemblySettings settings) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:1901)
    UnityEditor.Scripting.ScriptCompilation.EditorCompilation.GetTargetAssembliesWithScripts (UnityEditor.Scripting.ScriptCompilation.ScriptAssemblySettings settings) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:1770)
    UnityEditor.Scripting.ScriptCompilation.EditorCompilation.DeleteUnusedAssemblies (UnityEditor.Scripting.ScriptCompilation.ScriptAssemblySettings settings) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:1101)
    UnityEditor.Scripting.ScriptCompilation.EditorCompilation.CompileScripts (UnityEditor.Scripting.ScriptCompilation.ScriptAssemblySettings scriptAssemblySettings, System.String tempBuildDirectory, UnityEditor.Scripting.ScriptCompilation.EditorScriptCompilationOptions options, UnityEditor.Scripting.ScriptCompilation.EditorBuildRules+TargetAssembly[]& notCompiledTargetAssemblies, System.String[]& notCompiledScripts) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:1315)
    UnityEditor.Scripting.ScriptCompilation.EditorCompilation.CompileScripts (UnityEditor.Scripting.ScriptCompilation.EditorScriptCompilationOptions options, UnityEditor.BuildTargetGroup platformGroup, UnityEditor.BuildTarget platform) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:1275)
    UnityEditor.Scripting.ScriptCompilation.EditorCompilation.TickCompilationPipeline (UnityEditor.Scripting.ScriptCompilation.EditorScriptCompilationOptions options, UnityEditor.BuildTargetGroup platformGroup, UnityEditor.BuildTarget platform) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:1718)
    UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface+<TickCompilationPipeline>c__AnonStorey5.<>m__0 () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilationInterface.cs:371)
    UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface.EmitExceptionAsError[T] (System.Func`1[TResult] func, T returnValue) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilationInterface.cs:97)
    UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilationInterface.cs:371)
     
  20. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    @SteveKouts,

    Hello, I didn't test Unity 2019.2.17f, Ill check.
     
    SteveKouts likes this.
  21. SteveKouts

    SteveKouts

    Joined:
    Aug 23, 2012
    Posts:
    79
    Thank you!
     
  22. SpicyDinosaur

    SpicyDinosaur

    Joined:
    Oct 25, 2019
    Posts:
    5

    I'm doing the regular navmesh tutorial during lessons I have with the person who taught me c# so hopefully that will help me better understand things, but for now should I have both obstacle AND navigation modifier or just the latter? I'll reference Sweet Hot Pepper as soon as I am about to start, as well. Last time I checked it I couldn't see what I wasn't doing but maybe I'll notice something this time.

    Right now, with both obstacle and modifier on I'm not seeing a difference.

    EDIT: I'm dense, I had turned widgets off to be able to better see any changes, but that turned off the visual for the navmesh itself!
     
    Last edited: Apr 23, 2023
  23. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    Hi all.

    Just wanted to leave a comment that wiki is open for update and edit. I have little time to update documentation after every changes. While lately a see many PR on code, there no major update on wiki. We can do one page at a time)
     
    MaDDoX likes this.
  24. poliman

    poliman

    Joined:
    Feb 5, 2015
    Posts:
    29
    Hi,
    I'm just wondering if there is a built-in option to disable pushing the agents between going to the Target location.

    In other words if the agents are colliding with each other the one that is moving pushes the other ones aside when they are on the way to the Target. I wanted to make it like this that the agent that is moving if it collides with another agent just stops and maybe if the way to the Target is unblocked it moves again.

    Is it somewhere integrated in the scripts or I must write it myself, if so do you have any quick suggestions for it.
     
  25. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
  26. validol731

    validol731

    Joined:
    Mar 25, 2021
    Posts:
    1
    Hello. I've noticed an issue where the Mesh for the TileMap is calculated even where there are no tiles. If you're making a dungeon where rooms are of various shapes and connected by corridors, and all other space is empty, then there will be a lot of unused Mesh. A temporary solution is to fill the empty tiles with a transparent sprite and ignore it. However, it would be nice if it also ignored empty cells.

    upload_2023-6-8_1-12-52.png
     

    Attached Files:

    Last edited: Jun 8, 2023
  27. poliman

    poliman

    Joined:
    Feb 5, 2015
    Posts:
    29
  28. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    Great video you found. I didn't knew even a half of that
     
  29. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
  30. mizak

    mizak

    Joined:
    Jun 5, 2014
    Posts:
    14
    I have an issue that i've seen discussed a little but there doesn't seem to be a conclusive answer. When I build the path after generating a 2d navmesh on XY axis, I get very small values of z. The entity starts at a (6f,6f,0f) LocalTransform and moves to somewhere like (6f, 6.0000124f, -0.000123f) after building the path using navmeshquery.

    Is this an issue with the navmesh generation putting a tiny offset into the z axis? It seems like the polygons themselves have tiny z values for position when looking at the MapLocation function. I'm having trouble finding more info whether in the code or online.
     
  31. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    @mizak

    Disable position update and sync agent with player manually each frame.
     
  32. mizak

    mizak

    Joined:
    Jun 5, 2014
    Posts:
    14
    I'm using the UnityEngine.Experimental.AI with ECS NavMesh code, I don't think it uses the position update function. It hasn't updated the entity position yet when running the NavMeshQuery.MapLocation. It gets the polygon nearest the entity which seems to have that small z value. It is hard to get exact information because I'm not sure how to step through NavMesh related code. I wish I could get the exact polygon positions somehow. The debug statements on navmesh generation seem to show 0 z values as it shows:
    upload_2023-6-13_20-49-49.png

    Kind of at a loss here tbh.
     
  33. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    @mizak

    I have 0 knowledge on ECS and very little on Unity. You need to look in other parts of the forum. NavMesh Plus uses only "native" Unity system.
     
  34. developer_bigdipperstudio

    developer_bigdipperstudio

    Joined:
    Dec 31, 2014
    Posts:
    10
    Hi,

    I am using unity 2022.2.21 and follow the basic tutorial in https://github.com/h8man/NavMeshPlus/wiki/HOW-TO#nav-mesh-basics
    However when i attach the NavMesh CollectSources2d to NavMesh it shows Error of "NevMeshExtension requires a NavMeshSurface component"
    And in this siturartion when I clicked "Bake" the Nav Mesh Data will be all zeros.

    Please kindly help :(
     

    Attached Files:

    • 20.PNG
      20.PNG
      File size:
      188.8 KB
      Views:
      73
  35. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    Unity released Navigation.AI it messed up with NavMeshPlus component. New components have "Navigation" prefix instead of "NavMesh"
     
  36. developer_bigdipperstudio

    developer_bigdipperstudio

    Joined:
    Dec 31, 2014
    Posts:
    10
    Oh I missed the post. Thanks a lot!:)
    Does it mean that whenever we saw the "NavMesh Link", "NavMesh Modifier", "NavMesh Modifier Volume" and "NavMesh Surface" in the tutorials we can just simply change to "Navigation Link", "Navigation Modifier", "Navigation Modifier Volume" and "Navigation Surface" while other components just remain the same with "NavMesh" prefix?
     
  37. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    Yes, you are correct. You can distinguish by icons between packages)
     
  38. t90freelancer

    t90freelancer

    Joined:
    Aug 23, 2022
    Posts:
    1
    I installed AI Navigation in unity 2022.2.10f1. when i used navmesh surface i click bake and nothing happend
     
  39. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
  40. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    NavMeshPlus updated with consistent component naming "Navigation XXX", was tested with latest Unity LTS 2022.3.4. Also Wiki had minor updates.
     
  41. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    @mukulabdagiri

    It depends. NavMesh calculates word bounds, enable Debug logs to view world bound calculation.
     
  42. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    No, NavMeshBuilder doesn't support NGUI sprites, but it has nothing to do with Agent sprites
     
  43. DrVanillaCookie

    DrVanillaCookie

    Joined:
    Aug 23, 2021
    Posts:
    56
    Hello, when I import the package I'm getting 'NavMeshVisualizationSettings.showNavigation' is obsolete: 'showNavigation is no longer supported and will be removed.'

    I see someone already reported this, but that was in Feb; I'm on LTS 2022.3.9f1. Navmesh is working perfectly, but there's no blue grid. I got all the gizmos on, so I hope it's not just me.
     
  44. DrVanillaCookie

    DrVanillaCookie

    Joined:
    Aug 23, 2021
    Posts:
    56
    I double checked, the grid is definitely not showing up. I checked Unity's AI navmesh in a 3D scene, the blue grid is there.
     
  45. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    Got it. Ill take a look
     
  46. MonkeDev69

    MonkeDev69

    Joined:
    Apr 19, 2020
    Posts:
    3
    Hello, I'm using navigation modifier on destructible objects, everytime an object gets destroyed, I have to bake everything again to get a new correct navigation areas, Is there a better way?
     
  47. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    MonkeDev69 likes this.
  48. paulsotena50

    paulsotena50

    Joined:
    Sep 27, 2023
    Posts:
    2
    Hello! First of all - big thanks for making this package, it makes life much-much easier. Really nice job, awesome result!

    I have a question I'd like to ask, probably someone here can help me with my case.

    So I have proceduraly generated world, based on Tilemaps, it's extremely huge, but generated only once on game start, the Debug.Log says it has: "Sources 263241". But those are tiles only. I have a NavMesh gameobject, with Navigation Surface on it:

    upload_2023-9-27_12-22-58.png

    So basically this one bakes only a layer "Generated World" which is basically a tilemap, and it works perfectly, I really love it.

    The problem starts when I have to bake it once again, since the world is huge it takes up to 20-25 seconds to bake the whole scene, but I have to do it once I instantiated something (GameObject) on the scene. For example, if I place a building, I need to bake it once again and spend 20-25 seconds again. This is a bit frustrating, since the whole game is about building. So I created another NavMesh object with different navigation surface settings:

    upload_2023-9-27_12-25-48.png

    But it doesn't work, I assume it just not possible to put two different NavMeshes, but is there any solution to somehow solve this case?

    Thanks a lot in advance and for any advice :)

    PS.: For run-time baking I'm using a BuildNavMeshAsync() method, and when I have to update mesh on instantiating some object I'm using UpdateNavMesh(Surface2D.navMeshData);
     
  49. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    373
    Hello.

    1. You can have as many surfaces as you want, but you need to connect them with NavMeshLinks
    2. You need to benchmark on what part takes 30 second (baking process or sources collection?)
    3. You can use cache for sources, check https://github.com/h8man/RedHotSweetPepper
    4. You may use other approach, like sliding window https://github.com/Unity-Technologies/NavMeshComponents/tree/master/Assets/Examples/Scenes
    5. If you tilemap is square based - use override by grid to boost perfomance

    200k doesn't sound as much, I definitely used 12k in less than second. I need to verify my result, it was a long ago.
     
  50. paulsotena50

    paulsotena50

    Joined:
    Sep 27, 2023
    Posts:
    2
    Hey, thanks for your answer.

    I was trying to set up NavMeshLinks, but didn't manage to do them for my dynamic surfaces. Considering the benchmarking - to me it seems that source collection takes the most of the time. Baking itself doesn't. I was trying to use grid, but it didn't really help.

    Considering the cache - I was trying to implement it, found the script from your demo, but didn't manage to implement it, always getting the error "collectsourcescache2d is not defined". Imported your project and I can see the script, but can't see where it connected to (or where it is used).

    UPD.: Managed to implement cache. Updating it as it's in your project, it works now much faster, takes about couple of seconds. But still not smothless, will keep trying.

    UPD2: So I have a NavMesh1 for tilemaps, and NavMesh2 for all other gameobjects. My idea was that I will bake NavMesh1 only once, and then I will dynamically update NavMesh2 whenever I need to put any building on scene. Now I understand, that it won't work and I was dumb af. Expected result on the picture below. Still looking for a solution, now it takes about 2-3 seconds to bake a whole scene on instantiating a building. Is it possible to bake only specific area?

    upload_2023-9-27_16-13-9.png
     

    Attached Files:

    Last edited: Sep 27, 2023