How do you update a nav mesh at runtime with the new API? I haven't been able to find any decent examples or documentation on it. For example, if I spawn in a new object after baking the nav mesh, how do I update the nav mesh in the area around that object so that it can be walked on/avoided?
https://github.com/Unity-Technologies/NavMeshComponents/tree/master/Assets/Examples/Scripts Take those files. LocalNavMeshBuilder.cs && NavMeshSourceTag.cs LocalNavMeshBuilder = you setup the area NavMeshSourceTag = add to the floor/plane you want to bake the navmesh It does seem to work in some cases. As he stated in the video it does make sense to setup the LocalNavMeshBuilder Area first and at runtime add NavMeshSourceTag to your dynamic generated content. if you get the error message: Code (CSharp): Failed to create agent because it is not close enough to the NavMesh you can try to tweek the values in your navagent or make sure that you NPC/Player is really on the navmesh. i also experienced that there is a delay if you generate navmeshes at runtime so you could get those messages aswell.
That seems to be how to bake a nav mesh at runtime. What I'm trying to do is update a small part of it due to an object being instantiated/destroyed, without having to rebake the entire nav mesh.
This is what I'm trying to do as well, since my project needs to regenerate parts of a destroyable terrain. Did you find a solution to your issue?
@crimi Sorry, I guess I didn't pay attention to what you replied with. That's exactly what I'm looking for, thanks!
My only other question then is how to do NavMeshSourceTag for colliders instead of only meshes. I looked at the API for NavMeshBuildSource and it seems to only allow you to either manually specify the dimensions of a primitive collider, or to use a mesh. Is there no way for it to instead just use a primitive collider?
I did also figure out that you can change the script execution order. If you put those scripts LocalNavMeshBuilder.cs && NavMeshSourceTag.cs above the default time in the editor, they will execute first and you dont will have this error "Failed to create agent because it is not close enough to the NavMesh". https://docs.unity3d.com/Manual/class-ScriptExecution.html
i got this error when i try to use these scripts in scene "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
Currently trying to make the local navmesh builder and source tag work, I already posted a question at reddit, sometimes it does work but currently it doesn't work, while the day before yesterday it did, I will keep updating: https://www.reddit.com/r/Unity3D/comments/9il4ou/help_dynamic_navmesh_at_runtime_partly_working/
The navmesh is used for "static" or unchanging objects. No movement, not being destroyed or added at runtime. If you want an object that changes, add a "navmesh obstacle" component to it, which when used properly allows the object to alter the mesh as it changes/moves/is disabled.
I haven't had any issues updating the navmesh with the new NavMeshSurface component: Full rebuild from scratch (slow): Code (csharp): NavMeshSurface nm = GameObject.FindObjectOfType<NavMeshSurface>(); nm.BuildNavMesh(); Update only changed tiles (fast): Code (csharp): NavMeshSurface nm = GameObject.FindObjectOfType<NavMeshSurface>(); nm.UpdateNavMesh(nm.navMeshData);
you can use this package: Runtime NavMesh https://assetstore.unity.com/packages/tools/ai/runtime-navmesh-151397
You really want me to pay 30 for something that should be included in the engine by default? They focusing on some useless stuff while basic problems are still not solved - this is ridiculous !!!
For anyone wondering, you need to add this to your project to gain access to the additional navmesh API calls: https://github.com/Unity-Technologies/NavMeshComponents
Yeh... What mean changed tiles? Whole surface object as i see? I have flat 500x500units (tiled by 10x10) ground. And updating takes hundreds of milliseconds, so i have hube lag spike on it. Any way to make local changes faster?
Hi, You can look into Code (CSharp): nm.UpdateNavMesh(nm.navMeshData); It is using method Code (CSharp): var sources = CollectSources(); That my be your bottleneck. Profile this method and create new, that suite your need (like nm.UpdateNavMeshLight(nm.navMeshData)) As you can see, all you need is changed tiles, and call this method Code (CSharp): NavMeshBuilder.UpdateNavMeshDataAsync(data, GetBuildSettings(), sources, sourcesBounds);
Collect sources is takes only 0.5ms, 120ms takes WaitForJobGroupID. As i understand it must be async-multithread. But main thread stops, waiting for it.
Changed tiles is the tiles in "Override Tile Size" on NavMeshSurface component. The navmesh has white lines showing the tiles. For example, I have a 512 and a 2k size terrain with 256 tile size. I use NavMeshObstacle with carving for trees that disappear and it does not hitch the game. I don't know how carving works compared to UpdateNavMesh.
Is there any update on this? I am encountering the same kind of issue. I am using the LocalNavmeshBuilder and the NavmeshSourceTag scripts, but with a bigger map it takes too much to recalculate the entire navmesh. Is there a way to update just one part of the navmesh which is around the object that gets added or destroyed?
There was roadmap here I think https://portal.productboard.com/agr...523-progressive-rearchitecture-navmesh-baking
Actually it seem this was already possible but not documented https://github.com/Unity-Technologies/NavMeshComponents/issues/95#issuecomment-609466521
To be blunt, There was a function UpdateNavMeshData https://docs.unity3d.com/ScriptReference/AI.NavMeshBuilder.UpdateNavMeshData.html And it take NavMeshBuildSettings as one of parameter https://docs.unity3d.com/2021.2/Documentation/ScriptReference/AI.NavMeshBuildSettings.html However, since 2020.1.0b9 https://unity3d.com/unity/beta/2020.1.0b9 there is one undocumented property of this setting class preserveTilesOutsideBounds This is the property that allow us to update navmesh partially, making a bound and only update what's inside the bound, while, as its name suggest, preserving everything that was already generated outside of the bound You need to experiment and understand how it work with bounding box and voxel size. But I have play with it and yes, its work ps. The link was a github issue of the https://github.com/Unity-Technologies/NavMeshComponents repo. But that repo was kill the issue system and the unfinished things was all gone cc: @TrevorUnity could you please bring back the issue of that github repo. You could freeze it but you should not remove it, there was some info I could found there
Hello, This is the exact setup I am also using, placing obstacles that carve the navmesh around the player for each tree. It does not hitch the game at all. However, I observed that sometimes all agents nearby are stopping for a couple of frames after obstacles are despawned. NavMeshAgent.isPathStale is always false apparently. Did you see something like this happening too?
I have in a city builder game, but I didn't look into it. Maybe it's only if you are calling SetDestinaion every frame.
As of 2022 this page https://docs.unity3d.com/2022.2/Documentation/ScriptReference/AI.NavMeshBuildSettings.html still not documented preserveTilesOutsideBounds
Not in runtime, when i want to hit the bake it says that: Updating the NavMesh failed due to an excessive number of tiles. Try limiting the distance between surface objects or increasing either the tile size or the voxel size. After increasing values, same thing happened.