Rid
A server resource handle value; neither an owner nor a resource-existence check.
Rid is a struct containing an Id value. default(Rid) has Id = 0. Copying the value does not extend server-object lifetime. IsValid checks only Id != 0; FreeRid does not clear saved copies.
Release only server objects you created, using the appropriate server. A Rid obtained from Resource.GetRid() is borrowed: do not call FreeRid on it yourself. A saved RID does not keep the Resource itself alive either.
The complete synchronous example below creates a temporary PhysicsServer2D space. Use takes Action<Rid>, releases its space in finally and propagates callback exceptions to its caller. The callback borrows the handle only until it returns: do not free or retain it, and do not pass an async lambda.
using System;
using Reckfell;
public static class TemporaryPhysicsSpace
{
// The callback borrows the handle until it returns; it must not free or retain it.
public static void Use(Action<Rid> action)
{
ArgumentNullException.ThrowIfNull(action);
Rid owned = PhysicsServer2D.SpaceCreate();
if (!owned.IsValid)
throw new InvalidOperationException("Could not create a physics space.");
try
{
action(owned);
}
finally
{
PhysicsServer2D.FreeRid(owned);
owned = default;
}
}
}Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
RidConstructor
public Rid(ReckfellObject from);For a Resource, reads its existing handle through GetRid(). For another object type, including null at runtime, produces a zero RID. Does not create a server resource, duplicate the Resource or transfer ownership. Not every Resource supplies a nonzero RID.
| Name | Type | Default |
|---|---|---|
from | ReckfellObject | — |
fromResource whose GetRid() is read. An ordinary Entity is not converted to its server object by this constructor.
Properties2
IdProperty
public ulong Id { get; }Opaque 64-bit identifier; default(Rid) has value 0. This number is not an asset path, Entity ID or proof that a resource exists. Do not persist it as a reference between runs.
IsValidProperty
public bool IsValid { get; }Returns Id != 0. Does not query the server or check object existence, type or ownership. A saved copy can still return true after FreeRid; reset your own variable to default after release.
Methods6
Equals2 overloads
public bool Equals(Rid other);Compares the numeric Id values. Two zero RIDs are equal; equal nonzero values do not establish that the corresponding object still exists.
| Name | Type | Default |
|---|---|---|
other | Rid | — |
otherRID value to compare; no server query is made.
booltrue when the Id values match; otherwise false.
public override bool Equals(object? obj);Returns true only when obj is a boxed Rid with the same Id. Null, a ulong with the same number and a string containing the RID representation are not equal to this value.
| Name | Type | Default |
|---|---|---|
obj | object | — |
objObject to check for Rid type and value.
booltrue for a Rid with the same Id; false for another Id, another type or null.
GetHashCodeint
public override int GetHashCode();Computes HashCode.Combine(Id) for C# collections. Equal values have equal hashes within the current process; different values can collide. Do not use it as a persistent identifier or a resource-existence check.
int32-bit hash of Id; stability between runs is not guaranteed.
ToStringstring
public override string ToString();Creates RID(<Id>) with the decimal Id formatted using invariant culture; the zero value is RID(0). This is a diagnostic representation, not resource serialization or a way to restore the resource.
stringDiagnostic string such as RID(123); the current culture does not change the Id format.
op_Equalitybool
public static bool operator ==(Rid left, Rid right);Checks equality of the numeric Id values without querying the server. Comparison neither checks resource existence nor transfers ownership.
| Name | Type | Default |
|---|---|---|
left | Rid | — |
right | Rid | — |
leftLeft RID value.
rightRight RID value.
booltrue when the Id values match; otherwise false.
op_Inequalitybool
public static bool operator !=(Rid left, Rid right);Checks inequality of the numeric Id values without querying the server. Comparison neither checks resource existence nor transfers ownership.
| Name | Type | Default |
|---|---|---|
left | Rid | — |
right | Rid | — |
leftLeft RID value.
rightRight RID value.
booltrue when the Id values differ; otherwise false.