NavigationRegion2D on different layers affecting each other?

Godot Version

4.3

Question

I have 4 nav_region_2D from 1 to 4, and each layer has its own nav_agent_2D from 1 to 4.

Say I want the enemy to only use the 4th layer for navigation.

When 1/2 is off and 3/4 is on, the enemy moves well. (intended)

When 1/2 is on and 3/4 is off, enemy doesn’t move. (intended)

Now the problem is when all 4 layers are active at once. The enemy starts to spin and take weird pathing. This is unintended.

What could be causing this issue? I have made 100% sure that all Regions/Agents only have 1 layer active at one time and the are all on separate layers.

(
This is the print output after checking if a region/agent is active in layers from 1~32 with method get_navigation_layer_value() →
@NavigationRegion2D@852:<NavigationRegion2D#326132312885>1
@NavigationRegion2D@853:<NavigationRegion2D#326199421755>2
@NavigationRegion2D@854:<NavigationRegion2D#326266530605>3
@NavigationRegion2D@855:<NavigationRegion2D#326333639465>4
@NavigationAgent2D@858:<NavigationAgent2D#330561498147>1
@NavigationAgent2D@857:<NavigationAgent2D#330511166496>2
@NavigationAgent2D@860:<NavigationAgent2D#330662161449>3
@NavigationAgent2D@859:<NavigationAgent2D#330611829798>4

1/2/3/4 is the layer number, only prints if the layer is active.
)

The navigation_layers bitmask are for filtering region polygons in a path query.

They are NOT a (tilemap) layering system to stack regions and navigation mesh polygons over each other. The only way to separate them is to use different navigation maps.

Navigation meshes can not be “layered” or stacked on top of each other like visuals or physic shapes. Attempting to stack navigation meshes on the same navigation map will result in merge and logical errors that break the pathfinding.

1 Like

huh, interesting. So if I wanted to use different navigation regions for different purposes(like flying enemies/ground enemies), what should I do? Can you elaborate on the “different navigation map” part?

You create a navigation map for a different type with the NavigationServer2D and set the map active. Then you switch the NavigationRegion2D and the NavigationAgent2D to use this new map.

var new_map: RID = NavigationServer2D.map_create()
NavigationServer2D.map_set_active(new_map, true)

$NavigationRegion2D.set_navigation_map(new_map)
$NavigationAgent2D.set_navigation_map(new_map)

You do that for every kind of agent type that requires a different navigation mesh . e.g. small, normal, and large agents. If you only want to exclude certain regions from being used you can use the navigation_layers bitmask on the path query or NavigationAgent, but as soon as you need different navmesh geometry for the agents you need different maps.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.