- Home /
Instantiating a nav mesh obstacle makes all current nav mesh agents try to walk through a wall.
In summary, I am making a game with tower-defence elements, with creeps that use a navigation mesh to pathfind their way to the enemy base. The main issue is, when I create a tower that's nearby the path they would take, most of the creeps try to just turn around and try to force themselves through a wall, until they get pushed out by some other creep trying to do the same thing.
The towers have a Nav Mesh Obstacle component with "Carve" enabled (because otherwise they'd just stop in front of said tower), and I feel that it's re-generating the polygons that the navmesh is made of, and in that frame, the creeps AI just breaks. I have no clue how to fix this problem, any assistance or advice would be greatly appreciated.
Here's a video showing the problem, for those that need to see the issue to understand it (I wouldn't blame you).
https://www.youtube.com/watch?v=gAUSyAovHjE&feature=youtu.be
Hi @Pizzaboy10,
I have the same problem. Have you solved in any way?
Sorry but i have not. I dropped this project after not being able to fix this issue long ago. I had briefly considered forcing a navmesh grid to be split into squares of the same size of my towers but couldn't figure that out.
Answer by Harinezumi · Feb 02, 2018 at 05:02 AM
Hi!
Seems like creating a navmesh obstacle with carving at runtime invalidates the existing paths. You can try setting carve only stationary on, or disabling carving, or tell all of your navmesh agents to calculate a new path (with SetDestination()) when you place a new obstacle. I don't know if either will help, but based on my experience with navmeshes these could solve the issue.
EDIT
As none of these suggestions seem to help, maybe you can look into Unity's NavMesh Components which extends the navmesh functionality, or completely switch over to the A* star project (you don't have to buy the pro, the free version is already useful enough).
Sorry I can't give you better advice, I've been working with navmeshes for 2 years and they still don't always do what I want them to do (I'm looking at you, distance from destination logic >:( ).
Thanks for the reply. I would disable carving, but then the creeps would just mush up against the tower ins$$anonymous$$d of going around them. As for SetDestination(), I added that to a key input and nothing seemed to change when I pressed it. I guess whatever causes the agent to decide on a path still thinks going into the wall is the right path.
Slight side note: I tried moving the whole floor and walls thing over a little and the creeps acted in a similar manner, just in a different place. Still no idea why.
Try also turning on Carve only stationary (I guess your tower is stationary anyway). I know I had weird behaviour with my navmesh obstacles if Carve only stationary was off, even if they were already present at the beginning.
Carve only stationary is on by default. I tried turning it off just for the sake of it, but no difference. I think this might be an issue I can't fix myself.
Answer by ray2yar · Dec 31, 2018 at 02:21 PM
I'll suggest something that will work but it WON'T be performant. You can use a navneshsurface, and rebuild the navmesh each time a new tower is placed. There will be a noticeable stutter if you have a large play area with a high resolution. You'd need to change your towers to "not walkable" and take off the obstacle component. If the user places alot of towers sequentially there'll be a larger stutter.
Your answer
![](https://koobas.hobune.stream/wayback/20220612151752im_/https://answers.unity.com/themes/thub/images/avi.jpg)