Browse Source

Merge pull request #77110 from smix8/fix_agent_avoidance_pos_4.0

[4.0] Fix agent avoidance position not updated when entering SceneTree
Rémi Verschelde 2 years ago
parent
commit
5fdd5fa19d

+ 4 - 0
scene/2d/navigation_agent_2d.cpp

@@ -151,6 +151,10 @@ void NavigationAgent2D::_notification(int p_what) {
 			set_agent_parent(get_parent());
 			set_agent_parent(get_parent());
 			set_physics_process_internal(true);
 			set_physics_process_internal(true);
 
 
+			if (agent_parent && avoidance_enabled) {
+				NavigationServer2D::get_singleton()->agent_set_position(agent, agent_parent->get_global_position());
+			}
+
 #ifdef DEBUG_ENABLED
 #ifdef DEBUG_ENABLED
 			if (NavigationServer2D::get_singleton()->get_debug_enabled()) {
 			if (NavigationServer2D::get_singleton()->get_debug_enabled()) {
 				debug_path_dirty = true;
 				debug_path_dirty = true;

+ 3 - 0
scene/2d/navigation_obstacle_2d.cpp

@@ -63,6 +63,9 @@ void NavigationObstacle2D::_notification(int p_what) {
 		case NOTIFICATION_POST_ENTER_TREE: {
 		case NOTIFICATION_POST_ENTER_TREE: {
 			set_agent_parent(get_parent());
 			set_agent_parent(get_parent());
 			set_physics_process_internal(true);
 			set_physics_process_internal(true);
+			if (parent_node2d && parent_node2d->is_inside_tree()) {
+				NavigationServer2D::get_singleton()->agent_set_position(agent, parent_node2d->get_global_position());
+			}
 		} break;
 		} break;
 
 
 		case NOTIFICATION_EXIT_TREE: {
 		case NOTIFICATION_EXIT_TREE: {

+ 4 - 0
scene/3d/navigation_agent_3d.cpp

@@ -154,6 +154,10 @@ void NavigationAgent3D::_notification(int p_what) {
 			set_agent_parent(get_parent());
 			set_agent_parent(get_parent());
 			set_physics_process_internal(true);
 			set_physics_process_internal(true);
 
 
+			if (agent_parent && avoidance_enabled) {
+				NavigationServer3D::get_singleton()->agent_set_position(agent, agent_parent->get_global_position());
+			}
+
 #ifdef DEBUG_ENABLED
 #ifdef DEBUG_ENABLED
 			if (NavigationServer3D::get_singleton()->get_debug_enabled()) {
 			if (NavigationServer3D::get_singleton()->get_debug_enabled()) {
 				debug_path_dirty = true;
 				debug_path_dirty = true;

+ 3 - 0
scene/3d/navigation_obstacle_3d.cpp

@@ -62,6 +62,9 @@ void NavigationObstacle3D::_notification(int p_what) {
 		case NOTIFICATION_POST_ENTER_TREE: {
 		case NOTIFICATION_POST_ENTER_TREE: {
 			set_agent_parent(get_parent());
 			set_agent_parent(get_parent());
 			set_physics_process_internal(true);
 			set_physics_process_internal(true);
+			if (parent_node3d && parent_node3d->is_inside_tree()) {
+				NavigationServer3D::get_singleton()->agent_set_position(agent, parent_node3d->get_global_position());
+			}
 		} break;
 		} break;
 
 
 		case NOTIFICATION_EXIT_TREE: {
 		case NOTIFICATION_EXIT_TREE: {