Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Expose rid_allocate_id and rid_from_int64 #102529

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

beicause
Copy link
Contributor

@beicause beicause commented Feb 7, 2025

Adds GD.RidAllocateId and GD.RidFromInt64 in C#.

rid_allocate_id and rid_from_int64 provide a way to create rid, but they are missing in C#.(https://docs.godotengine.org/en/latest/tutorials/scripting/c_sharp/c_sharp_differences.html)

@beicause beicause requested a review from a team as a code owner February 7, 2025 12:58
@AThousandShips AThousandShips added this to the 4.x milestone Feb 7, 2025
@raulsntos
Copy link
Member

The documentation of these methods say they are mainly used from native extensions to implement servers, which is not an use case supported with C# as a scripting language. So I'm wondering about the specific need for these methods from C#, could you share your specific use case?

@beicause
Copy link
Contributor Author

beicause commented Feb 9, 2025

They are indeed rarely used in scripts. One use case I think is deralization of Rid, because the Id field of Rid is meaningless without rid_from_int64.

@raulsntos
Copy link
Member

I don't think it makes sense to serialize RIDs, Godot always serializes them as RID(). The RIDs assigned to your resources are not guaranteed to stay the same on every execution, see this note from the RID documentation:

Note: RIDs are only useful during the current session. It won't correspond to a similar resource if sent over a network, or loaded from a file at a later time.

@beicause
Copy link
Contributor Author

beicause commented Feb 10, 2025

As long as the rid is not released, it is still accessible, and I think this should be allowed at runtime, for example serializing a custom struct that contains an rid (although it is often unnecessary to do so). I also found although the documentation states that rid is not supported serialization, var_to_bytes and bytes_to_var can correctly handle rid (godotengine/godot-docs#10662).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants