From 47b39ce4c2d01e05aa630302c6cfdb7bb99ec106 Mon Sep 17 00:00:00 2001 From: smix8 <52464204+smix8@users.noreply.github.com> Date: Sat, 13 Aug 2022 19:46:12 +0200 Subject: [PATCH] Fix NavigationObstacle nodes not registering to default navigation map Fix NavigationObstacle nodes not registering to default navigation map. --- scene/2d/navigation_obstacle_2d.cpp | 7 ++++++- scene/3d/navigation_obstacle.cpp | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp index 1a9f2dba803..c5ac9b33e2a 100644 --- a/scene/2d/navigation_obstacle_2d.cpp +++ b/scene/2d/navigation_obstacle_2d.cpp @@ -139,7 +139,12 @@ void NavigationObstacle2D::set_navigation(Navigation2D *p_nav) { } navigation = p_nav; - Navigation2DServer::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid()); + + if (navigation != nullptr) { + Navigation2DServer::get_singleton()->agent_set_map(agent, navigation->get_rid()); + } else if (parent_node2d && parent_node2d->is_inside_tree()) { + Navigation2DServer::get_singleton()->agent_set_map(agent, parent_node2d->get_world_2d()->get_navigation_map()); + } } void NavigationObstacle2D::set_navigation_node(Node *p_nav) { diff --git a/scene/3d/navigation_obstacle.cpp b/scene/3d/navigation_obstacle.cpp index 78594cee180..1376a08d521 100644 --- a/scene/3d/navigation_obstacle.cpp +++ b/scene/3d/navigation_obstacle.cpp @@ -145,7 +145,12 @@ void NavigationObstacle::set_navigation(Navigation *p_nav) { } navigation = p_nav; - NavigationServer::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid()); + + if (navigation != nullptr) { + NavigationServer::get_singleton()->agent_set_map(agent, navigation->get_rid()); + } else if (parent_spatial && parent_spatial->is_inside_tree()) { + NavigationServer::get_singleton()->agent_set_map(agent, parent_spatial->get_world()->get_navigation_map()); + } } void NavigationObstacle::set_navigation_node(Node *p_nav) {