Skip to content

Commit 5fdd5fa

Browse files
authored
Merge pull request #77110 from smix8/fix_agent_avoidance_pos_4.0
[4.0] Fix agent avoidance position not updated when entering SceneTree
2 parents bce0491 + 5296b91 commit 5fdd5fa

4 files changed

Lines changed: 14 additions & 0 deletions

File tree

scene/2d/navigation_agent_2d.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ void NavigationAgent2D::_notification(int p_what) {
151151
set_agent_parent(get_parent());
152152
set_physics_process_internal(true);
153153

154+
if (agent_parent && avoidance_enabled) {
155+
NavigationServer2D::get_singleton()->agent_set_position(agent, agent_parent->get_global_position());
156+
}
157+
154158
#ifdef DEBUG_ENABLED
155159
if (NavigationServer2D::get_singleton()->get_debug_enabled()) {
156160
debug_path_dirty = true;

scene/2d/navigation_obstacle_2d.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ void NavigationObstacle2D::_notification(int p_what) {
6363
case NOTIFICATION_POST_ENTER_TREE: {
6464
set_agent_parent(get_parent());
6565
set_physics_process_internal(true);
66+
if (parent_node2d && parent_node2d->is_inside_tree()) {
67+
NavigationServer2D::get_singleton()->agent_set_position(agent, parent_node2d->get_global_position());
68+
}
6669
} break;
6770

6871
case NOTIFICATION_EXIT_TREE: {

scene/3d/navigation_agent_3d.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ void NavigationAgent3D::_notification(int p_what) {
154154
set_agent_parent(get_parent());
155155
set_physics_process_internal(true);
156156

157+
if (agent_parent && avoidance_enabled) {
158+
NavigationServer3D::get_singleton()->agent_set_position(agent, agent_parent->get_global_position());
159+
}
160+
157161
#ifdef DEBUG_ENABLED
158162
if (NavigationServer3D::get_singleton()->get_debug_enabled()) {
159163
debug_path_dirty = true;

scene/3d/navigation_obstacle_3d.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ void NavigationObstacle3D::_notification(int p_what) {
6262
case NOTIFICATION_POST_ENTER_TREE: {
6363
set_agent_parent(get_parent());
6464
set_physics_process_internal(true);
65+
if (parent_node3d && parent_node3d->is_inside_tree()) {
66+
NavigationServer3D::get_singleton()->agent_set_position(agent, parent_node3d->get_global_position());
67+
}
6568
} break;
6669

6770
case NOTIFICATION_EXIT_TREE: {

0 commit comments

Comments
 (0)