Any way to get area that NavigationMesh baked around?

Godot Version

v4.3.stable.official [77dcf97d8]

Question

When baking a mesh, you can include your objects that it should bake around, such as by class, or any child mesh/collider. However, is there any way to get the area that was avoided, as that changes based on NavigationAgent's radius, height, etc.?

What do you need the area for?
Are you referring to, like, the area in units? or a literal Area2D or Area3D object that you are using as an obstacle?

If you need the navigation agent to be aware of what area they’re currently avoiding, that could be difficult. Say you want the area in units of the nearest obstacle to your agent. If you’re using a small number of agents and the obstacle list doesn’t change that much, maybe using NavigationServer3D.map_get_obstacles would be a good way to search for the closest obstacle (by comparing NavigationServer3D.obstacle_get_position with your agent’s position), then use NavigationServer3D.obstacle_get_radius as a proxy for the “area”, and do whatever you need with that. However, this would perform very poorly with lots of agents or very dynamic obstacle lists, since you would probably need to refresh the obstacle list and make a lot of comparisons to find the closest obstacle.

This also feels a little counterproductive. From what I understand, the whole point of the navigation system is to calculate relationships between agents, the nav mesh, and obstacles efficiently and internally, even if it doesn’t expose certain things to you directly. It really depends on what you need the area for.

Make a second navigation mesh and invert all the avoided objects and included objects. It’ll be weird, but it should get you something. I agree with @roboticy3 though, there’s probably an easier way to do whatever you’re trying to do.

For context what I am trying to do:
I am attempting to create a game where players are able to move units by clicking on the floor. I was able to make units not path through each other by baking a NavigationMesh every time a unit’s movement is started and finished.
However, now I am trying to allow certain units to path through friendly units. My first approach was to create a NavigationRegion around each unit, and depending on their team, use navigation layers to allow or disallow agents from using that region. That, however, did not really work, as agents began taking unexpected turns when coming in and out of that unit’s region. I thought this might be because I was not creating a precise enough area, hence my question. I was going to use that area to bake a precise region in an effort to solve strange pathfinding.
After a couple of days of researching, I think the best course of action would be to just create multiple NavigationMeshes and swap between them depending on which type of unit I am navigating, e.g. unit from team 1, unit from team 2, etc.