summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmix8 <52464204+smix8@users.noreply.github.com>2021-04-20 01:56:04 +0200
committersmix8 <52464204+smix8@users.noreply.github.com>2021-04-20 01:56:04 +0200
commita491071c2487448a1e730e7357bbabb93a0c8100 (patch)
treef11ae90573b89ef4973c5462d954d59dd4f39a73
parent8ba06e3161315f1af4207443df86b82d4dd6f06c (diff)
Fix broken NavigationAgent2D collision avoidance callbacks
Fix broken NavigationAgent2D collision avoidance callbacks
-rw-r--r--scene/2d/navigation_agent_2d.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp
index a18687afed..3f8201b559 100644
--- a/scene/2d/navigation_agent_2d.cpp
+++ b/scene/2d/navigation_agent_2d.cpp
@@ -35,6 +35,8 @@
#include "servers/navigation_server_2d.h"
void NavigationAgent2D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("get_rid"), &NavigationAgent2D::get_rid);
+
ClassDB::bind_method(D_METHOD("set_target_desired_distance", "desired_distance"), &NavigationAgent2D::set_target_desired_distance);
ClassDB::bind_method(D_METHOD("get_target_desired_distance"), &NavigationAgent2D::get_target_desired_distance);
@@ -88,9 +90,11 @@ void NavigationAgent2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY: {
agent_parent = Object::cast_to<Node2D>(get_parent());
-
- NavigationServer2D::get_singleton()->agent_set_callback(agent, this, "_avoidance_done");
-
+ if (agent_parent != nullptr) {
+ // place agent on navigation map first or else the RVO agent callback creation fails silently later
+ NavigationServer2D::get_singleton()->agent_set_map(get_rid(), agent_parent->get_world_2d()->get_navigation_map());
+ NavigationServer2D::get_singleton()->agent_set_callback(agent, this, "_avoidance_done");
+ }
set_physics_process_internal(true);
} break;
case NOTIFICATION_EXIT_TREE: {