From b03f6bc1707d286de555e168d1465bb0d9b4bb44 Mon Sep 17 00:00:00 2001 From: smix8 <52464204+smix8@users.noreply.github.com> Date: Wed, 18 May 2022 22:14:48 +0200 Subject: [PATCH 1/8] Remove arbitrary NavigationMesh bake property limits Lowers or removes the slider limits and steps from NavigationMesh resources and changes some default values to better work with realistic unit sizes by default. (cherry picked from commit cda93057f73ad937deacb8200cf27f4996ed8918) --- doc/classes/NavigationMesh.xml | 12 ++++++------ scene/resources/navigation_mesh.cpp | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/doc/classes/NavigationMesh.xml b/doc/classes/NavigationMesh.xml index 3bd6805117b..04889ed0318 100644 --- a/doc/classes/NavigationMesh.xml +++ b/doc/classes/NavigationMesh.xml @@ -74,25 +74,25 @@ - + The minimum floor to ceiling height that will still allow the floor area to be considered walkable. [b]Note:[/b] While baking, this value will be rounded up to the nearest multiple of [member cell/height]. - + The minimum ledge height that is considered to still be traversable. [b]Note:[/b] While baking, this value will be rounded down to the nearest multiple of [member cell/height]. The maximum slope that is considered walkable, in degrees. - + The distance to erode/shrink the walkable area of the heightfield away from obstructions. [b]Note:[/b] While baking, this value will be rounded up to the nearest multiple of [member cell/size]. - + The Y axis cell size to use for fields. - + The XZ plane cell size to use for fields. @@ -138,7 +138,7 @@ Any regions with a size smaller than this will be merged with larger regions if possible. [b]Note:[/b] This value will be squared to calculate the number of cells. For example, a value of 20 will set the number of cells to 400. - + The minimum size of a region for it to be created. [b]Note:[/b] This value will be squared to calculate the minimum number of cells allowed to form isolated island areas. For example, a value of 8 will set the number of cells to 64. diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index 72d4ede5db7..cf9d8882820 100644 --- a/scene/resources/navigation_mesh.cpp +++ b/scene/resources/navigation_mesh.cpp @@ -485,12 +485,12 @@ void NavigationMesh::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "geometry/source_geometry_mode", PROPERTY_HINT_ENUM, "Navmesh Children, Group With Children, Group Explicit"), "set_source_geometry_mode", "get_source_geometry_mode"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "geometry/source_group_name"), "set_source_group_name", "get_source_group_name"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "cell/size", PROPERTY_HINT_RANGE, "0.1,1.0,0.01,or_greater"), "set_cell_size", "get_cell_size"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "cell/height", PROPERTY_HINT_RANGE, "0.1,1.0,0.01,or_greater"), "set_cell_height", "get_cell_height"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "agent/height", PROPERTY_HINT_RANGE, "0.1,5.0,0.01,or_greater"), "set_agent_height", "get_agent_height"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "agent/radius", PROPERTY_HINT_RANGE, "0.1,5.0,0.01,or_greater"), "set_agent_radius", "get_agent_radius"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "agent/max_climb", PROPERTY_HINT_RANGE, "0.1,5.0,0.01,or_greater"), "set_agent_max_climb", "get_agent_max_climb"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "agent/max_slope", PROPERTY_HINT_RANGE, "0.0,90.0,0.1"), "set_agent_max_slope", "get_agent_max_slope"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "cell/size", PROPERTY_HINT_RANGE, "0.01,500.0,0.01,or_greater"), "set_cell_size", "get_cell_size"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "cell/height", PROPERTY_HINT_RANGE, "0.01,500.0,0.01,or_greater"), "set_cell_height", "get_cell_height"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "agent/height", PROPERTY_HINT_RANGE, "0.0,500.0,0.01,or_greater"), "set_agent_height", "get_agent_height"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "agent/radius", PROPERTY_HINT_RANGE, "0.0,500.0,0.01,or_greater"), "set_agent_radius", "get_agent_radius"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "agent/max_climb", PROPERTY_HINT_RANGE, "0.0,500.0,0.01,or_greater"), "set_agent_max_climb", "get_agent_max_climb"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "agent/max_slope", PROPERTY_HINT_RANGE, "0.02,90.0,0.01"), "set_agent_max_slope", "get_agent_max_slope"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "region/min_size", PROPERTY_HINT_RANGE, "0.0,150.0,0.01,or_greater"), "set_region_min_size", "get_region_min_size"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "region/merge_size", PROPERTY_HINT_RANGE, "0.0,150.0,0.01,or_greater"), "set_region_merge_size", "get_region_merge_size"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "edge/max_length", PROPERTY_HINT_RANGE, "0.0,50.0,0.01,or_greater"), "set_edge_max_length", "get_edge_max_length"); @@ -536,13 +536,13 @@ void NavigationMesh::_validate_property(PropertyInfo &property) const { } NavigationMesh::NavigationMesh() { - cell_size = 0.3f; - cell_height = 0.2f; - agent_height = 2.0f; - agent_radius = 0.6f; - agent_max_climb = 0.9f; + cell_size = 0.25f; + cell_height = 0.25f; + agent_height = 1.5f; + agent_radius = 0.5f; + agent_max_climb = 0.25f; agent_max_slope = 45.0f; - region_min_size = 8.0f; + region_min_size = 2.0f; region_merge_size = 20.0f; edge_max_length = 12.0f; edge_max_error = 1.3f; From 8b9f532f785ac5f9d2ddf9b81b484aec6a09ad5f Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 20 May 2022 10:47:29 +0800 Subject: [PATCH 2/8] Fix editor crash when opening scene with CSGMesh (cherry picked from commit de93286b1defaae24bfeb52e4d1eb4d75e36392a) --- modules/csg/csg_gizmos.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/csg/csg_gizmos.cpp b/modules/csg/csg_gizmos.cpp index 1f34a6ad7ee..46ba78aec45 100644 --- a/modules/csg/csg_gizmos.cpp +++ b/modules/csg/csg_gizmos.cpp @@ -379,9 +379,11 @@ void CSGShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { if (cs->is_root_shape()) { Array csg_meshes = cs->get_meshes(); - Ref csg_mesh = csg_meshes[1]; - if (csg_mesh.is_valid()) { - p_gizmo->add_collision_triangles(csg_mesh->generate_triangle_mesh()); + if (csg_meshes.size() == 2) { + Ref csg_mesh = csg_meshes[1]; + if (csg_mesh.is_valid()) { + p_gizmo->add_collision_triangles(csg_mesh->generate_triangle_mesh()); + } } } From 47ead8504adc1719bf3a60e4f71b11efb3d8b1b4 Mon Sep 17 00:00:00 2001 From: Daniel Kariv Date: Thu, 19 May 2022 11:55:14 +0300 Subject: [PATCH 3/8] add check for selection when try to push a meta. Add a check for when we select a text but end on a link. Before it would act as if we just click an link, but now it changes it so if we click-drag over a link, we could select it (and not move to other page). (cherry picked from commit e6c909b489282337328bca90b167b6f8158c1de9) --- scene/gui/rich_text_label.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 1f1117345ac..6dc8f7aa5dd 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -1233,7 +1233,7 @@ void RichTextLabel::_gui_input(Ref p_event) { } selection.click = nullptr; - if (!b->is_doubleclick() && !scroll_updated) { + if (!b->is_doubleclick() && !scroll_updated && !selection.active) { int line = 0; Item *item = nullptr; From 61278499aa8cdf734ed93cc30f66209c7f571d98 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Fri, 20 May 2022 14:12:09 +0200 Subject: [PATCH 4/8] Tweak 64-bit integer overflow message to mention that it's a signed type (cherry picked from commit 7b5bf3af192be83afab19bbfcd029d97af0da8cd) --- core/ustring.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/ustring.cpp b/core/ustring.cpp index 64af6894827..782457a952f 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -1739,7 +1739,7 @@ int String::hex_to_int(bool p_with_prefix) const { } // Check for overflow/underflow, with special case to ensure INT32_MIN does not result in error bool overflow = ((hex > INT32_MAX / 16) && (sign == 1 || (sign == -1 && hex != (INT32_MAX >> 4) + 1))) || (sign == -1 && hex == (INT32_MAX >> 4) + 1 && c > '0'); - ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + *this + " as integer, provided value is " + (sign == 1 ? "too big." : "too small.")); + ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + *this + " as a 32-bit signed integer, since the value is " + (sign == 1 ? "too large." : "too small.")); hex *= 16; hex += n; s++; @@ -1781,7 +1781,7 @@ int64_t String::hex_to_int64(bool p_with_prefix) const { return 0; } bool overflow = ((hex > INT64_MAX / 16) && (sign == 1 || (sign == -1 && hex != (INT64_MAX >> 4) + 1))) || (sign == -1 && hex == (INT64_MAX >> 4) + 1 && c > '0'); - ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as 64-bit integer, provided value is " + (sign == 1 ? "too big." : "too small.")); + ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as a 64-bit signed integer, since the value is " + (sign == 1 ? "too large." : "too small.")); hex *= 16; hex += n; s++; @@ -1823,7 +1823,7 @@ int64_t String::bin_to_int64(bool p_with_prefix) const { } // Check for overflow/underflow, with special case to ensure INT64_MIN does not result in error bool overflow = ((binary > INT64_MAX / 2) && (sign == 1 || (sign == -1 && binary != (INT64_MAX >> 1) + 1))) || (sign == -1 && binary == (INT64_MAX >> 1) + 1 && c > '0'); - ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as 64-bit integer, provided value is " + (sign == 1 ? "too big." : "too small.")); + ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as a 64-bit signed integer, since the value is " + (sign == 1 ? "too large." : "too small.")); binary *= 2; binary += n; s++; @@ -1846,7 +1846,7 @@ int String::to_int() const { CharType c = operator[](i); if (c >= '0' && c <= '9') { bool overflow = (integer > INT32_MAX / 10) || (integer == INT32_MAX / 10 && ((sign == 1 && c > '7') || (sign == -1 && c > '8'))); - ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + *this + " as integer, provided value is " + (sign == 1 ? "too big." : "too small.")); + ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + *this + " as a 32-bit signed integer, since the value is " + (sign == 1 ? "too large." : "too small.")); integer *= 10; integer += c - '0'; @@ -1872,7 +1872,7 @@ int64_t String::to_int64() const { CharType c = operator[](i); if (c >= '0' && c <= '9') { bool overflow = (integer > INT64_MAX / 10) || (integer == INT64_MAX / 10 && ((sign == 1 && c > '7') || (sign == -1 && c > '8'))); - ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as 64-bit integer, provided value is " + (sign == 1 ? "too big." : "too small.")); + ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as a 64-bit signed integer, since the value is " + (sign == 1 ? "too large." : "too small.")); integer *= 10; integer += c - '0'; @@ -1901,7 +1901,7 @@ int String::to_int(const char *p_str, int p_len) { char c = p_str[i]; if (c >= '0' && c <= '9') { bool overflow = (integer > INT32_MAX / 10) || (integer == INT32_MAX / 10 && ((sign == 1 && c > '7') || (sign == -1 && c > '8'))); - ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + String(p_str).substr(0, to) + " as integer, provided value is " + (sign == 1 ? "too big." : "too small.")); + ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + String(p_str).substr(0, to) + " as a 32-bit signed integer, since the value is " + (sign == 1 ? "too large." : "too small.")); integer *= 10; integer += c - '0'; @@ -2220,7 +2220,7 @@ int64_t String::to_int(const CharType *p_str, int p_len) { while (*str && str != limit) { number += *(str++); } - ERR_FAIL_V_MSG(sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + number + " as integer, provided value is " + (sign == 1 ? "too big." : "too small.")); + ERR_FAIL_V_MSG(sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + number + " as a 64-bit signed integer, since the value is " + (sign == 1 ? "too large." : "too small.")); } integer *= 10; integer += c - '0'; From 4a03bc8f750d0ebced252438144bb6ce3d22699a Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Sun, 22 May 2022 15:49:42 +0800 Subject: [PATCH 5/8] Update last min size when Control becomes visible (cherry picked from commit 4ac999cc3fa0d7740356aaafe7ab44da2b16e7dd) --- scene/gui/control.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index cfe7e7a73d0..2d608195eb4 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -652,6 +652,7 @@ void Control::_notification(int p_notification) { //remove modalness } else { data.minimum_size_valid = false; + _update_minimum_size(); _size_changed(); } From 548c511f57aaf91aa7444ae43e84b9db0388cd79 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Fri, 20 May 2022 16:07:49 +0200 Subject: [PATCH 6/8] Tweak the disabled files text color in FileDialog for readability Contrast rate is still fairly low, but the text needs to be easy enough to distinguish from non-disabled items. (cherry picked from commit 8962d2760d05a2027d65d104bf3763edb828c52a) --- doc/classes/FileDialog.xml | 2 +- scene/resources/default_theme/default_theme.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/classes/FileDialog.xml b/doc/classes/FileDialog.xml index 0484d69eda3..e2226cf128b 100644 --- a/doc/classes/FileDialog.xml +++ b/doc/classes/FileDialog.xml @@ -130,7 +130,7 @@ The color modulation applied to the file icon. - + The color tint for disabled files (when the [FileDialog] is used in open folder mode). diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 3a13494c0fc..1616968228e 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -784,7 +784,7 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_icon("file", "FileDialog", make_icon(icon_file_png)); theme->set_color("folder_icon_modulate", "FileDialog", Color(1, 1, 1)); theme->set_color("file_icon_modulate", "FileDialog", Color(1, 1, 1)); - theme->set_color("files_disabled", "FileDialog", Color(0, 0, 0, 0.7)); + theme->set_color("files_disabled", "FileDialog", Color(1, 1, 1, 0.25)); // ColorPicker From 4855fc67aa9edec5df25fdf11dabcda4e8e08061 Mon Sep 17 00:00:00 2001 From: kleonc <9283098+kleonc@users.noreply.github.com> Date: Sun, 22 May 2022 16:17:59 +0200 Subject: [PATCH 7/8] EditorPropertyArray Fix crash when drag-reordering elements in the inspector (cherry picked from commit 33b29704926f623f97402e0cfbf2591a163b8ab6) --- editor/editor_properties_array_dict.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index af7435d35ad..bf5f952902b 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -618,11 +618,16 @@ void EditorPropertyArray::_reorder_button_gui_input(const Ref &p_eve Variant array = object->get_array(); int size = array.call("size"); - if ((reorder_to_index == 0 && mm->get_relative().y < 0.0f) || (reorder_to_index == size - 1 && mm->get_relative().y > 0.0f)) { + // Cumulate the mouse delta, many small changes (dragging slowly) should result in reordering at some point. + reorder_mouse_y_delta += mm->get_relative().y; + + // Reordering is done by moving the dragged element by +1/-1 index at a time based on the cumulated mouse delta so if + // already at the array bounds make sure to ignore the remaining out of bounds drag (by resetting the cumulated delta). + if ((reorder_to_index == 0 && reorder_mouse_y_delta < 0.0f) || (reorder_to_index == size - 1 && reorder_mouse_y_delta > 0.0f)) { + reorder_mouse_y_delta = 0.0f; return; } - reorder_mouse_y_delta += mm->get_relative().y; float required_y_distance = 20.0f * EDSCALE; if (ABS(reorder_mouse_y_delta) > required_y_distance) { int direction = reorder_mouse_y_delta > 0.0f ? 1 : -1; From 8df9fd076f3bc960657111773f52f61b4a654ec1 Mon Sep 17 00:00:00 2001 From: smix8 <52464204+smix8@users.noreply.github.com> Date: Fri, 20 May 2022 22:55:27 +0200 Subject: [PATCH 8/8] Process NavigationAgent2D/3D avoidance on demand only Changes NavigationAgent avoidance callback to a toggle that is disabled by default. Also fixes a few missing descriptions / wrong warnings. (cherry picked from commit 7f3688603cb3662e425cb7a1dce15459162c1dc6) --- doc/classes/NavigationAgent.xml | 5 ++++- doc/classes/NavigationAgent2D.xml | 5 ++++- scene/2d/navigation_agent_2d.cpp | 22 ++++++++++++++++++++-- scene/2d/navigation_agent_2d.h | 5 +++++ scene/3d/navigation_agent.cpp | 22 ++++++++++++++++++++-- scene/3d/navigation_agent.h | 5 +++++ 6 files changed, 58 insertions(+), 6 deletions(-) diff --git a/doc/classes/NavigationAgent.xml b/doc/classes/NavigationAgent.xml index fdc680b8c16..03941689ae3 100644 --- a/doc/classes/NavigationAgent.xml +++ b/doc/classes/NavigationAgent.xml @@ -48,7 +48,7 @@ - Returns the object's [RID]. + Returns the [RID] of this agent on the [NavigationServer]. @@ -101,6 +101,9 @@ The agent height offset to match the navigation mesh height. + + If [code]true[/code] the agent is registered for an RVO avoidance callback on the [NavigationServer]. When [method set_velocity] is used and the processing is completed a [code]safe_velocity[/code] Vector3 is received with a signal connection to [signal velocity_computed]. Avoidance processing with many registered agents has a significant performance cost and should only be enabled on agents that currently require it. + Ignores collisions on the Y axis. Must be [code]true[/code] to move on a horizontal plane. diff --git a/doc/classes/NavigationAgent2D.xml b/doc/classes/NavigationAgent2D.xml index c2bce448801..bfbcbca7320 100644 --- a/doc/classes/NavigationAgent2D.xml +++ b/doc/classes/NavigationAgent2D.xml @@ -48,7 +48,7 @@ - Returns the object's [RID]. + Returns the [RID] of this agent on the [Navigation2DServer]. @@ -98,6 +98,9 @@ + + If [code]true[/code] the agent is registered for an RVO avoidance callback on the [Navigation2DServer]. When [method set_velocity] is used and the processing is completed a [code]safe_velocity[/code] Vector2 is received with a signal connection to [signal velocity_computed]. Avoidance processing with many registered agents has a significant performance cost and should only be enabled on agents that currently require it. + The maximum number of neighbors for the agent to consider. diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index a00b4d10a89..a126704215b 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -37,6 +37,9 @@ void NavigationAgent2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_rid"), &NavigationAgent2D::get_rid); + ClassDB::bind_method(D_METHOD("set_avoidance_enabled", "enabled"), &NavigationAgent2D::set_avoidance_enabled); + ClassDB::bind_method(D_METHOD("get_avoidance_enabled"), &NavigationAgent2D::get_avoidance_enabled); + ClassDB::bind_method(D_METHOD("set_target_desired_distance", "desired_distance"), &NavigationAgent2D::set_target_desired_distance); ClassDB::bind_method(D_METHOD("get_target_desired_distance"), &NavigationAgent2D::get_target_desired_distance); @@ -82,6 +85,7 @@ void NavigationAgent2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "time_horizon", PROPERTY_HINT_RANGE, "0.1,10000,0.01"), "set_time_horizon", "get_time_horizon"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_speed", PROPERTY_HINT_RANGE, "0.1,100000,0.01"), "set_max_speed", "get_max_speed"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "path_max_distance", PROPERTY_HINT_RANGE, "10,100,1"), "set_path_max_distance", "get_path_max_distance"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "avoidance_enabled"), "set_avoidance_enabled", "get_avoidance_enabled"); ADD_SIGNAL(MethodInfo("path_changed")); ADD_SIGNAL(MethodInfo("target_reached")); @@ -94,7 +98,7 @@ void NavigationAgent2D::_notification(int p_what) { case NOTIFICATION_READY: { agent_parent = Object::cast_to(get_parent()); - Navigation2DServer::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); + set_avoidance_enabled(avoidance_enabled); // Search the navigation node and set it { @@ -153,6 +157,7 @@ NavigationAgent2D::NavigationAgent2D() : agent_parent(nullptr), navigation(nullptr), agent(RID()), + avoidance_enabled(false), target_desired_distance(1.0), path_max_distance(3.0), velocity_submitted(false), @@ -171,6 +176,19 @@ NavigationAgent2D::~NavigationAgent2D() { agent = RID(); // Pointless } +void NavigationAgent2D::set_avoidance_enabled(bool p_enabled) { + avoidance_enabled = p_enabled; + if (avoidance_enabled) { + Navigation2DServer::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); + } else { + Navigation2DServer::get_singleton()->agent_set_callback(agent, nullptr, "_avoidance_done"); + } +} + +bool NavigationAgent2D::get_avoidance_enabled() const { + return avoidance_enabled; +} + void NavigationAgent2D::set_navigation(Navigation2D *p_nav) { if (navigation == p_nav) { return; // Pointless @@ -297,7 +315,7 @@ void NavigationAgent2D::_avoidance_done(Vector3 p_new_velocity) { String NavigationAgent2D::get_configuration_warning() const { if (!Object::cast_to(get_parent())) { - return TTR("The NavigationAgent2D can be used only under a Node2D node."); + return TTR("The NavigationAgent2D can be used only under a Node2D inheriting parent node."); } return String(); diff --git a/scene/2d/navigation_agent_2d.h b/scene/2d/navigation_agent_2d.h index ff508c9733a..93d12dc6cdf 100644 --- a/scene/2d/navigation_agent_2d.h +++ b/scene/2d/navigation_agent_2d.h @@ -46,6 +46,8 @@ class NavigationAgent2D : public Node { RID agent; RID map_before_pause; + bool avoidance_enabled; + real_t target_desired_distance; real_t radius; real_t neighbor_dist; @@ -87,6 +89,9 @@ public: return agent; } + void set_avoidance_enabled(bool p_enabled); + bool get_avoidance_enabled() const; + void set_target_desired_distance(real_t p_dd); real_t get_target_desired_distance() const { return target_desired_distance; diff --git a/scene/3d/navigation_agent.cpp b/scene/3d/navigation_agent.cpp index 23d2a9a5434..92f5528d595 100644 --- a/scene/3d/navigation_agent.cpp +++ b/scene/3d/navigation_agent.cpp @@ -37,6 +37,9 @@ void NavigationAgent::_bind_methods() { ClassDB::bind_method(D_METHOD("get_rid"), &NavigationAgent::get_rid); + ClassDB::bind_method(D_METHOD("set_avoidance_enabled", "enabled"), &NavigationAgent::set_avoidance_enabled); + ClassDB::bind_method(D_METHOD("get_avoidance_enabled"), &NavigationAgent::get_avoidance_enabled); + ClassDB::bind_method(D_METHOD("set_target_desired_distance", "desired_distance"), &NavigationAgent::set_target_desired_distance); ClassDB::bind_method(D_METHOD("get_target_desired_distance"), &NavigationAgent::get_target_desired_distance); @@ -90,6 +93,7 @@ void NavigationAgent::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_speed", PROPERTY_HINT_RANGE, "0.1,10000,0.01"), "set_max_speed", "get_max_speed"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "path_max_distance", PROPERTY_HINT_RANGE, "0.01,100,0.1"), "set_path_max_distance", "get_path_max_distance"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_y"), "set_ignore_y", "get_ignore_y"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "avoidance_enabled"), "set_avoidance_enabled", "get_avoidance_enabled"); ADD_SIGNAL(MethodInfo("path_changed")); ADD_SIGNAL(MethodInfo("target_reached")); @@ -102,7 +106,7 @@ void NavigationAgent::_notification(int p_what) { case NOTIFICATION_READY: { agent_parent = Object::cast_to(get_parent()); - NavigationServer::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); + set_avoidance_enabled(avoidance_enabled); // Search the navigation node and set it { @@ -161,6 +165,7 @@ NavigationAgent::NavigationAgent() : agent_parent(nullptr), navigation(nullptr), agent(RID()), + avoidance_enabled(false), target_desired_distance(1.0), navigation_height_offset(0.0), path_max_distance(3.0), @@ -181,6 +186,19 @@ NavigationAgent::~NavigationAgent() { agent = RID(); // Pointless } +void NavigationAgent::set_avoidance_enabled(bool p_enabled) { + avoidance_enabled = p_enabled; + if (avoidance_enabled) { + NavigationServer::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); + } else { + NavigationServer::get_singleton()->agent_set_callback(agent, nullptr, "_avoidance_done"); + } +} + +bool NavigationAgent::get_avoidance_enabled() const { + return avoidance_enabled; +} + void NavigationAgent::set_navigation(Navigation *p_nav) { if (navigation == p_nav) { return; // Pointless @@ -315,7 +333,7 @@ void NavigationAgent::_avoidance_done(Vector3 p_new_velocity) { String NavigationAgent::get_configuration_warning() const { if (!Object::cast_to(get_parent())) { - return TTR("The NavigationAgent can be used only under a spatial node."); + return TTR("The NavigationAgent can be used only under a Spatial inheriting parent node."); } return String(); diff --git a/scene/3d/navigation_agent.h b/scene/3d/navigation_agent.h index 5c5d67c9354..b2c57326f44 100644 --- a/scene/3d/navigation_agent.h +++ b/scene/3d/navigation_agent.h @@ -46,6 +46,8 @@ class NavigationAgent : public Node { RID agent; RID map_before_pause; + bool avoidance_enabled; + real_t target_desired_distance; real_t radius; real_t navigation_height_offset; @@ -89,6 +91,9 @@ public: return agent; } + void set_avoidance_enabled(bool p_enabled); + bool get_avoidance_enabled() const; + void set_target_desired_distance(real_t p_dd); real_t get_target_desired_distance() const { return target_desired_distance;