Fix enabling NavigationRegion3D saved disabled

This PR fixes issue #83364 by always registering the region when it enters the tree, and instead using region_set_enabled to control whether its enabled. The same logical changes have been applied to NavigationRegion2D.
This commit is contained in:
Malcolm Nixon 2023-10-14 23:17:57 -04:00
parent a574c0296b
commit 0646b230e4
2 changed files with 19 additions and 19 deletions

View file

@ -497,20 +497,18 @@ void NavigationRegion2D::_region_enter_navigation_map() {
return; return;
} }
if (enabled) { if (map_override.is_valid()) {
if (map_override.is_valid()) { NavigationServer2D::get_singleton()->region_set_map(region, map_override);
NavigationServer2D::get_singleton()->region_set_map(region, map_override); for (uint32_t i = 0; i < constrain_avoidance_obstacles.size(); i++) {
for (uint32_t i = 0; i < constrain_avoidance_obstacles.size(); i++) { if (constrain_avoidance_obstacles[i].is_valid()) {
if (constrain_avoidance_obstacles[i].is_valid()) { NavigationServer2D::get_singleton()->obstacle_set_map(constrain_avoidance_obstacles[i], map_override);
NavigationServer2D::get_singleton()->obstacle_set_map(constrain_avoidance_obstacles[i], map_override);
}
} }
} else { }
NavigationServer2D::get_singleton()->region_set_map(region, get_world_2d()->get_navigation_map()); } else {
for (uint32_t i = 0; i < constrain_avoidance_obstacles.size(); i++) { NavigationServer2D::get_singleton()->region_set_map(region, get_world_2d()->get_navigation_map());
if (constrain_avoidance_obstacles[i].is_valid()) { for (uint32_t i = 0; i < constrain_avoidance_obstacles.size(); i++) {
NavigationServer2D::get_singleton()->obstacle_set_map(constrain_avoidance_obstacles[i], get_world_2d()->get_navigation_map()); if (constrain_avoidance_obstacles[i].is_valid()) {
} NavigationServer2D::get_singleton()->obstacle_set_map(constrain_avoidance_obstacles[i], get_world_2d()->get_navigation_map());
} }
} }
} }
@ -523,6 +521,8 @@ void NavigationRegion2D::_region_enter_navigation_map() {
} }
} }
NavigationServer2D::get_singleton()->region_set_enabled(region, enabled);
queue_redraw(); queue_redraw();
} }

View file

@ -356,17 +356,17 @@ void NavigationRegion3D::_region_enter_navigation_map() {
return; return;
} }
if (enabled) { if (map_override.is_valid()) {
if (map_override.is_valid()) { NavigationServer3D::get_singleton()->region_set_map(region, map_override);
NavigationServer3D::get_singleton()->region_set_map(region, map_override); } else {
} else { NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
}
} }
current_global_transform = get_global_transform(); current_global_transform = get_global_transform();
NavigationServer3D::get_singleton()->region_set_transform(region, current_global_transform); NavigationServer3D::get_singleton()->region_set_transform(region, current_global_transform);
NavigationServer3D::get_singleton()->region_set_enabled(region, enabled);
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
if (NavigationServer3D::get_singleton()->get_debug_navigation_enabled()) { if (NavigationServer3D::get_singleton()->get_debug_navigation_enabled()) {
_update_debug_mesh(); _update_debug_mesh();