Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Fix NavigationObstacle errors #56600

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions scene/2d/navigation_obstacle_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,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();

// Search the navigation node and set it
{
Expand Down Expand Up @@ -104,6 +104,7 @@ NavigationObstacle2D::NavigationObstacle2D() :
navigation(nullptr),
agent(RID()) {
agent = Navigation2DServer::get_singleton()->agent_create();
initialize_agent();
}

NavigationObstacle2D::~NavigationObstacle2D() {
Expand Down Expand Up @@ -148,7 +149,7 @@ void NavigationObstacle2D::initialize_agent() {
void NavigationObstacle2D::reevaluate_agent_radius() {
if (!estimate_agent_radius()) {
Navigation2DServer::get_singleton()->agent_set_radius(agent, radius);
} else if (parent_node2d) {
} else if (parent_node2d && parent_node2d->is_inside_tree()) {
Navigation2DServer::get_singleton()->agent_set_radius(agent, estimate_agent_radius());
}
}
Expand Down
9 changes: 5 additions & 4 deletions scene/3d/navigation_obstacle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ void NavigationObstacle::_validate_property(PropertyInfo &p_property) const {

void NavigationObstacle::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY: {
initialize_agent();
case NOTIFICATION_ENTER_TREE: {
parent_spatial = Object::cast_to<Spatial>(get_parent());
reevaluate_agent_radius();

// Search the navigation node and set it
{
Expand Down Expand Up @@ -111,6 +111,7 @@ NavigationObstacle::NavigationObstacle() :
navigation(nullptr),
agent(RID()) {
agent = NavigationServer::get_singleton()->agent_create();
initialize_agent();
}

NavigationObstacle::~NavigationObstacle() {
Expand All @@ -129,7 +130,7 @@ void NavigationObstacle::set_navigation(Navigation *p_nav) {

void NavigationObstacle::set_navigation_node(Node *p_nav) {
Navigation *nav = Object::cast_to<Navigation>(p_nav);
ERR_FAIL_COND(nav);
ERR_FAIL_NULL(nav);
set_navigation(nav);
}

Expand All @@ -155,7 +156,7 @@ void NavigationObstacle::initialize_agent() {
void NavigationObstacle::reevaluate_agent_radius() {
if (!estimate_radius) {
NavigationServer::get_singleton()->agent_set_radius(agent, radius);
} else if (parent_spatial) {
} else if (parent_spatial && parent_spatial->is_inside_tree()) {
NavigationServer::get_singleton()->agent_set_radius(agent, estimate_agent_radius());
}
}
Expand Down