diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-01-28 23:25:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-28 23:25:55 +0100 |
commit | 1c6f0aa3a0952a38dd6d4ef416b3007b888fff17 (patch) | |
tree | 5741ad6a15256c78a774491a21736c9c6ea53394 /scene/2d | |
parent | 2a5b136de20c9c7f51abb8a90b9e9d8dc57152ac (diff) | |
parent | 9bda2d5859fd0fa62e837c26fc465e0a5ffbc60a (diff) |
Merge pull request #56601 from Scony/fix-navigation-obstacle-errors
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/navigation_obstacle_2d.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp index e5df089771..fad54070a5 100644 --- a/scene/2d/navigation_obstacle_2d.cpp +++ b/scene/2d/navigation_obstacle_2d.cpp @@ -53,9 +53,9 @@ void NavigationObstacle2D::_validate_property(PropertyInfo &p_property) const { void NavigationObstacle2D::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_READY: { - initialize_agent(); + case NOTIFICATION_ENTER_TREE: { parent_node2d = Object::cast_to<Node2D>(get_parent()); + reevaluate_agent_radius(); if (parent_node2d != 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(), parent_node2d->get_world_2d()->get_navigation_map()); @@ -83,6 +83,7 @@ void NavigationObstacle2D::_notification(int p_what) { NavigationObstacle2D::NavigationObstacle2D() { agent = NavigationServer2D::get_singleton()->agent_create(); + initialize_agent(); } NavigationObstacle2D::~NavigationObstacle2D() { @@ -110,7 +111,7 @@ void NavigationObstacle2D::initialize_agent() { void NavigationObstacle2D::reevaluate_agent_radius() { if (!estimate_radius) { NavigationServer2D::get_singleton()->agent_set_radius(agent, radius); - } else if (parent_node2d) { + } else if (parent_node2d && parent_node2d->is_inside_tree()) { NavigationServer2D::get_singleton()->agent_set_radius(agent, estimate_agent_radius()); } } |