Skip to content

Expose helper methods for converting UIDs #106717

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

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/io/resource_uid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ void ResourceUID::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_id_path", "id"), &ResourceUID::get_id_path);
ClassDB::bind_method(D_METHOD("remove_id", "id"), &ResourceUID::remove_id);

ClassDB::bind_static_method("ResourceUID", D_METHOD("uid_to_path", "uid"), &ResourceUID::uid_to_path);
ClassDB::bind_static_method("ResourceUID", D_METHOD("path_to_uid", "path"), &ResourceUID::path_to_uid);
ClassDB::bind_static_method("ResourceUID", D_METHOD("ensure_path", "path_or_uid"), &ResourceUID::ensure_path);

BIND_CONSTANT(INVALID_ID)
}
ResourceUID *ResourceUID::singleton = nullptr;
Expand Down
21 changes: 21 additions & 0 deletions doc/classes/ResourceUID.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
Like [method create_id], but the UID is seeded with the provided [param path] and project name. UIDs generated for that path will be always the same within the current project.
</description>
</method>
<method name="ensure_path" qualifiers="static">
<return type="String" />
<param index="0" name="path_or_uid" type="String" />
<description>
Returns a path, converting [param path_or_uid] if necessary. Prints an error if provided an invalid UID.
</description>
</method>
<method name="get_id_path" qualifiers="const">
<return type="String" />
<param index="0" name="id" type="int" />
Expand All @@ -55,6 +62,13 @@
Converts the given UID to a [code]uid://[/code] string value.
</description>
</method>
<method name="path_to_uid" qualifiers="static">
<return type="String" />
<param index="0" name="path" type="String" />
<description>
Converts the provided resource [param path] to a UID. Returns the unchanged path if it has no associated UID.
</description>
</method>
<method name="remove_id">
<return type="void" />
<param index="0" name="id" type="int" />
Expand All @@ -79,6 +93,13 @@
Extracts the UID value from the given [code]uid://[/code] string.
</description>
</method>
<method name="uid_to_path" qualifiers="static">
<return type="String" />
<param index="0" name="uid" type="String" />
<description>
Converts the provided [param uid] to a path. Prints an error if the UID is invalid.
</description>
</method>
</methods>
<constants>
<constant name="INVALID_ID" value="-1">
Expand Down