From aadf33efd8a79a038b842dc91c63784302efd753 Mon Sep 17 00:00:00 2001 From: smix8 <52464204+smix8@users.noreply.github.com> Date: Thu, 6 Apr 2023 16:32:49 +0200 Subject: [PATCH] Fix NavigationObstacles not being added to avoidance simulation Fixes NavigationObstacles not being added to avoidance simulation. --- scene/2d/navigation_obstacle_2d.cpp | 7 +++++++ scene/2d/navigation_obstacle_2d.h | 2 ++ scene/3d/navigation_obstacle_3d.cpp | 7 +++++++ scene/3d/navigation_obstacle_3d.h | 2 ++ 4 files changed, 18 insertions(+) diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp index d7ef77e25b9..2366cb696ef 100644 --- a/scene/2d/navigation_obstacle_2d.cpp +++ b/scene/2d/navigation_obstacle_2d.cpp @@ -196,13 +196,20 @@ void NavigationObstacle2D::set_agent_parent(Node *p_agent_parent) { } else { NavigationServer2D::get_singleton()->agent_set_map(get_rid(), parent_node2d->get_world_2d()->get_navigation_map()); } + // Need to register Callback as obstacle requires a valid Callback to be added to avoidance simulation. + NavigationServer2D::get_singleton()->agent_set_callback(get_rid(), callable_mp(this, &NavigationObstacle2D::_avoidance_done)); reevaluate_agent_radius(); } else { parent_node2d = nullptr; NavigationServer2D::get_singleton()->agent_set_map(get_rid(), RID()); + NavigationServer2D::get_singleton()->agent_set_callback(agent, Callable()); } } +void NavigationObstacle2D::_avoidance_done(Vector3 p_new_velocity) { + // Dummy function as obstacle requires a valid Callback to be added to avoidance simulation. +} + void NavigationObstacle2D::set_navigation_map(RID p_navigation_map) { if (map_override == p_navigation_map) { return; diff --git a/scene/2d/navigation_obstacle_2d.h b/scene/2d/navigation_obstacle_2d.h index 12ddcaf2192..f856c481b0e 100644 --- a/scene/2d/navigation_obstacle_2d.h +++ b/scene/2d/navigation_obstacle_2d.h @@ -75,6 +75,8 @@ public: PackedStringArray get_configuration_warnings() const override; + void _avoidance_done(Vector3 p_new_velocity); // Dummy + private: void initialize_agent(); void reevaluate_agent_radius(); diff --git a/scene/3d/navigation_obstacle_3d.cpp b/scene/3d/navigation_obstacle_3d.cpp index 85b3c164cc6..14d93fb0e03 100644 --- a/scene/3d/navigation_obstacle_3d.cpp +++ b/scene/3d/navigation_obstacle_3d.cpp @@ -203,13 +203,20 @@ void NavigationObstacle3D::set_agent_parent(Node *p_agent_parent) { } else { NavigationServer3D::get_singleton()->agent_set_map(get_rid(), parent_node3d->get_world_3d()->get_navigation_map()); } + // Need to register Callback as obstacle requires a valid Callback to be added to avoidance simulation. + NavigationServer3D::get_singleton()->agent_set_callback(get_rid(), callable_mp(this, &NavigationObstacle3D::_avoidance_done)); reevaluate_agent_radius(); } else { parent_node3d = nullptr; NavigationServer3D::get_singleton()->agent_set_map(get_rid(), RID()); + NavigationServer3D::get_singleton()->agent_set_callback(agent, Callable()); } } +void NavigationObstacle3D::_avoidance_done(Vector3 p_new_velocity) { + // Dummy function as obstacle requires a valid Callback to be added to avoidance simulation. +} + void NavigationObstacle3D::set_navigation_map(RID p_navigation_map) { if (map_override == p_navigation_map) { return; diff --git a/scene/3d/navigation_obstacle_3d.h b/scene/3d/navigation_obstacle_3d.h index 416b32c026e..c5a9d737f6c 100644 --- a/scene/3d/navigation_obstacle_3d.h +++ b/scene/3d/navigation_obstacle_3d.h @@ -74,6 +74,8 @@ public: PackedStringArray get_configuration_warnings() const override; + void _avoidance_done(Vector3 p_new_velocity); // Dummy + private: void initialize_agent(); void reevaluate_agent_radius();