Merge pull request #48030 from smix8/issue_47337_broken_navagent2d_callback

This commit is contained in:
Rémi Verschelde 2021-04-23 10:13:44 +02:00 committed by GitHub
commit bd7a92ec23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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: {