Sometimes NPC's go around obstacles, sometimes the pathfinding tries to go through them

Godot Version

4.2

Question

When this scene is loaded, it loads any saved objects first, then it sets the NavigationRegion Polygon to NavigationPolygon.new(), then it bakes it. Can someone please tell me why some NPC’s path’s go around the objects and some try and go through them?
image

Here is a better Picture:
image

my guess is this has more to do with the configuration of the npc that isn’t acting correctly. if it’s working for one of them then I would venture that your implementation is correct however I would imagine there is some small difference between the npcs settings causing the variance. maybe try removing the one that doesnt work and use a copy of the one that does instead and if you find it works correctly then that pretty much confirms it.

This layout and path looks like you have both the baked NavigationRegion2D navigation mesh and the TileMap build-in navigation mesh regions active at the same time. Disable the TileMap navigation layer if you use a NavigationRegion2D to bake the TileMap, else you have 2+ overlapping navigation mesh surfaces creating conflicts.

Navigation polygons are usually baked ahead of time, not when the scene loads.

My guess would be that one agent determines its path before the navigation polygon appears (or with the old one?) and the second does pathfinding on the “updated” one.

I see. I thought if I used, group with children, and made the Objects children of the tilemap, it would make the navigation always the size of the wooden tiles with holes where the objects are. I was wondering why it looked like there were 2 layers. I will try this thank you.

The peoblem is, the player can place more objects down and the NPCs need to to navigate around them. So the signal, children ordered changed, is connected to the function bake navigation polygon. It updates throughout gameplay

It shouldnt be because the NPCs arent scenes in the world scene. They are loaded depending on which NPC’ have entered the house.

I think that’s what navigation obstacles are for? No luck there?

I believe so. I am not using obstacles because baking the polygon already omits the Static Bodies in the Navigation. Also, i think not using Obstacles is better for performance.

I haven’t had time to work on it yet. But i believe my mistake was baking the polygon with the Wooden Floor Tiles included. I thought this would automatically create a nav polygon the prrfect size of the floor map. But this caused the NavAgent on NPCs to consider all areas with those tiles as free to navigate. I think the solution will be to manually create a nav polygon for each room size upgrade and not assign navigation to the wooden tiles. If this makes sense.

That makes sense, mixing two navigation systems may behave in weird ways. Either use navmesh or tiles, I’d say.

Also - obstacles indeed affect performance. But baking a navmesh is definitely more expensive. Seems a little backwards to me.