From b11708c50df4e465777e64a47b63be16b10fa565 Mon Sep 17 00:00:00 2001
From: smix8 <52464204+smix8@users.noreply.github.com>
Date: Sat, 14 May 2022 23:33:09 +0200
Subject: [PATCH] Expose NavigationObstacle2D/3D get_rid() and add config
warning
Exposes get_rid() function for scripting.
Adds configuration warning when obstacle is used with not intended static body parent.
(cherry picked from commit 001d89223f1377717d2b3d5ec453ff8dd3604182)
---
doc/classes/NavigationObstacle.xml | 6 ++++++
doc/classes/NavigationObstacle2D.xml | 6 ++++++
scene/2d/navigation_obstacle_2d.cpp | 8 ++++++++
scene/3d/navigation_obstacle.cpp | 9 ++++++++-
4 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/doc/classes/NavigationObstacle.xml b/doc/classes/NavigationObstacle.xml
index f58e9e6d47f..9480f6f5182 100644
--- a/doc/classes/NavigationObstacle.xml
+++ b/doc/classes/NavigationObstacle.xml
@@ -15,6 +15,12 @@
Returns the [Navigation] node that the obstacle is using for its navigation system.
+
+
+
+ Returns the [RID] of this obstacle on the [NavigationServer].
+
+
diff --git a/doc/classes/NavigationObstacle2D.xml b/doc/classes/NavigationObstacle2D.xml
index 0f75132c083..54913d59f4c 100644
--- a/doc/classes/NavigationObstacle2D.xml
+++ b/doc/classes/NavigationObstacle2D.xml
@@ -15,6 +15,12 @@
Returns the [Navigation2D] node that the obstacle is using for its navigation system.
+
+
+
+ Returns the [RID] of this obstacle on the [Navigation2DServer].
+
+
diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp
index f89ee8756bc..2d7e331227d 100644
--- a/scene/2d/navigation_obstacle_2d.cpp
+++ b/scene/2d/navigation_obstacle_2d.cpp
@@ -36,8 +36,11 @@
#include "servers/navigation_2d_server.h"
void NavigationObstacle2D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("get_rid"), &NavigationObstacle2D::get_rid);
+
ClassDB::bind_method(D_METHOD("set_navigation", "navigation"), &NavigationObstacle2D::set_navigation_node);
ClassDB::bind_method(D_METHOD("get_navigation"), &NavigationObstacle2D::get_navigation_node);
+
ClassDB::bind_method(D_METHOD("set_estimate_radius", "estimate_radius"), &NavigationObstacle2D::set_estimate_radius);
ClassDB::bind_method(D_METHOD("is_radius_estimated"), &NavigationObstacle2D::is_radius_estimated);
ClassDB::bind_method(D_METHOD("set_radius", "radius"), &NavigationObstacle2D::set_radius);
@@ -136,6 +139,11 @@ String NavigationObstacle2D::get_configuration_warning() const {
return TTR("The NavigationObstacle2D only serves to provide collision avoidance to a Node2D object.");
}
+ if (Object::cast_to(get_parent())) {
+ return TTR("The NavigationObstacle2D is intended for constantly moving bodies like KinematicBody2D or RigidBody2D as it creates only an RVO avoidance radius and does not follow scene geometry exactly."
+ "\nNot constantly moving or complete static objects should be captured with a refreshed NavigationPolygon so agents can not only avoid them but also move along those objects outline at high detail");
+ }
+
return String();
}
diff --git a/scene/3d/navigation_obstacle.cpp b/scene/3d/navigation_obstacle.cpp
index e1cadfb0346..29cc16f357e 100644
--- a/scene/3d/navigation_obstacle.cpp
+++ b/scene/3d/navigation_obstacle.cpp
@@ -36,6 +36,8 @@
#include "servers/navigation_server.h"
void NavigationObstacle::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("get_rid"), &NavigationObstacle::get_rid);
+
ClassDB::bind_method(D_METHOD("set_navigation", "navigation"), &NavigationObstacle::set_navigation_node);
ClassDB::bind_method(D_METHOD("get_navigation"), &NavigationObstacle::get_navigation_node);
ClassDB::bind_method(D_METHOD("is_radius_estimated"), &NavigationObstacle::is_radius_estimated);
@@ -140,7 +142,12 @@ Node *NavigationObstacle::get_navigation_node() const {
String NavigationObstacle::get_configuration_warning() const {
if (!Object::cast_to(get_parent())) {
- return TTR("The NavigationObstacle only serves to provide collision avoidance to a spatial object.");
+ return TTR("The NavigationObstacle only serves to provide collision avoidance to a Spatial inheriting parent object.");
+ }
+
+ if (Object::cast_to(get_parent())) {
+ return TTR("The NavigationObstacle is intended for constantly moving bodies like KinematicBody3D or RigidBody3D as it creates only an RVO avoidance radius and does not follow scene geometry exactly."
+ "\nNot constantly moving or complete static objects should be (re)baked to a NavigationMesh so agents can not only avoid them but also move along those objects outline at high detail");
}
return String();