diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs
index eb6fbdda77..45da8c09a2 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs
@@ -533,6 +533,9 @@ namespace Godot.NativeInterop
public static partial int godotsharp_node_path_get_subname_count(in godot_node_path p_self);
+ public static partial void godotsharp_node_path_slice(scoped in godot_node_path p_self, int p_begin, int p_end,
+ out godot_node_path r_result);
+
public static partial godot_bool godotsharp_node_path_is_absolute(in godot_node_path p_self);
public static partial godot_bool godotsharp_node_path_equals(in godot_node_path p_self, in godot_node_path p_other);
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NodePath.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NodePath.cs
index 0af640533d..08f1380ccc 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NodePath.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NodePath.cs
@@ -274,6 +274,31 @@ namespace Godot
return NativeFuncs.godotsharp_node_path_get_subname_count(self);
}
+ ///
+ /// Returns the slice of the NodePath, from begin (inclusive) to end (exclusive), as a
+ /// new NodePath.
+ /// The absolute value of begin and end will be clamped to the sum of
+ /// GetNameCount and
+ /// GetSubNameCount, so the default value for end makes it
+ /// slice to the end of the NodePath by default (i.e. path.Slice(1) is a shorthand for
+ /// path.Slice(1, path.GetNameCount() + path.GetSubNameCount())).
+ /// If either begin or end are negative, they will be relative to the end of the NodePath
+ /// (i.e. path.Slice(0, -2) is shorthand for
+ /// path.Slice(0, path.GetNameCount() + path.GetSubNameCount() - 2)).
+ ///
+ /// The index of the name or subname at which to start the slice.
+ /// The index (exclusive) of the name or subname at which to end the slice.
+ /// A slice of the NodePath bounded by begin and end.
+ public NodePath Slice(int begin, int end = Int32.MaxValue)
+ {
+ var self = (godot_node_path)NativeValue;
+
+ NativeFuncs.godotsharp_node_path_slice(self, begin, end, out godot_node_path slicedNodePath);
+
+ using (slicedNodePath)
+ return new NodePath(slicedNodePath);
+ }
+
///
/// Returns if the node path is absolute (as opposed to relative),
/// which means that it starts with a slash character (/). Absolute node paths can
diff --git a/modules/mono/glue/runtime_interop.cpp b/modules/mono/glue/runtime_interop.cpp
index 71f64eb81f..227f966f1b 100644
--- a/modules/mono/glue/runtime_interop.cpp
+++ b/modules/mono/glue/runtime_interop.cpp
@@ -1331,6 +1331,10 @@ int32_t godotsharp_node_path_get_subname_count(const NodePath *p_self) {
return p_self->get_subname_count();
}
+void godotsharp_node_path_slice(const NodePath *p_self, int32_t p_begin, int32_t p_end, NodePath *r_result) {
+ memnew_placement(r_result, NodePath(p_self->slice(p_begin, p_end)));
+}
+
bool godotsharp_node_path_is_absolute(const NodePath *p_self) {
return p_self->is_absolute();
}
@@ -1712,6 +1716,7 @@ static const void *unmanaged_callbacks[]{
(void *)godotsharp_node_path_get_name_count,
(void *)godotsharp_node_path_get_subname,
(void *)godotsharp_node_path_get_subname_count,
+ (void *)godotsharp_node_path_slice,
(void *)godotsharp_node_path_is_absolute,
(void *)godotsharp_node_path_equals,
(void *)godotsharp_node_path_hash,