diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rid.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rid.cs
index 150eb98fc7d..350626389b3 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rid.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rid.cs
@@ -6,13 +6,17 @@ using Godot.NativeInterop;
namespace Godot
{
///
- /// The Rid type is used to access the unique integer ID of a resource.
- /// They are opaque, which means they do not grant access to the associated
- /// resource by themselves. They are used by and with the low-level Server
- /// classes such as .
+ /// The RID type is used to access a low-level resource by its unique ID.
+ /// RIDs are opaque, which means they do not grant access to the resource
+ /// by themselves. They are used by the low-level server classes, such as
+ /// , ,
+ /// , etc.
+ ///
+ /// A low-level resource may correspond to a high-level ,
+ /// such as or
///
[StructLayout(LayoutKind.Sequential)]
- public readonly struct Rid
+ public readonly struct Rid : IEquatable
{
private readonly ulong _id; // Default is 0
@@ -28,15 +32,73 @@ namespace Godot
=> _id = from is Resource res ? res.GetRid()._id : default;
///
- /// Returns the ID of the referenced resource.
+ /// Returns the ID of the referenced low-level resource.
///
/// The ID of the referenced resource.
public ulong Id => _id;
+ ///
+ /// Returns if the is not 0.
+ ///
+ /// Whether or not the ID is valid.
+ public bool IsValid => _id != 0;
+
+ ///
+ /// Returns if both s are equal,
+ /// which means they both refer to the same low-level resource.
+ ///
+ /// The left RID.
+ /// The right RID.
+ /// Whether or not the RIDs are equal.
+ public static bool operator ==(Rid left, Rid right)
+ {
+ return left.Equals(right);
+ }
+
+ ///
+ /// Returns if the s are not equal.
+ ///
+ /// The left RID.
+ /// The right RID.
+ /// Whether or not the RIDs are equal.
+ public static bool operator !=(Rid left, Rid right)
+ {
+ return !left.Equals(right);
+ }
+
+ ///
+ /// Returns if this RID and are equal.
+ ///
+ /// The other object to compare.
+ /// Whether or not the color and the other object are equal.
+ public override readonly bool Equals(object obj)
+ {
+ return obj is Rid other && Equals(other);
+ }
+
+ ///
+ /// Returns if the RIDs are equal.
+ ///
+ /// The other RID.
+ /// Whether or not the RIDs are equal.
+ public readonly bool Equals(Rid other)
+ {
+ return _id == other.Id;
+ }
+
+ ///
+ /// Serves as the hash function for .
+ ///
+ /// A hash code for this RID.
+ public override readonly int GetHashCode()
+ {
+ return HashCode.Combine(_id);
+ }
+
///
/// Converts this to a string.
///
/// A string representation of this Rid.
- public override string ToString() => $"Rid({Id})";
+ public override string ToString() => $"RID({Id})";
}
}