diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-04-23 10:13:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-23 10:13:44 +0200 |
commit | bd7a92ec23a1d33795c5310652f54c529516cd29 (patch) | |
tree | 482b3409402f4bb83386e055f150cad7bfddafd5 /scene/2d | |
parent | 6cfbf3633883f2bd1088f050b8a5d9e0db622e90 (diff) | |
parent | a491071c2487448a1e730e7357bbabb93a0c8100 (diff) |
Merge pull request #48030 from smix8/issue_47337_broken_navagent2d_callback
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/navigation_agent_2d.cpp | 10 |
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: { |