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

Conversation

KoBeWi
Copy link
Member

@KoBeWi KoBeWi commented May 22, 2025

Related #105414 (comment)

Exposes the static methods for converting between paths and UIDs. They are widely used in the engine and didn't change since they were added, so there is no reason to keep them unexposed. They make working with UIDs more convenient.

@KoBeWi KoBeWi added this to the 4.5 milestone May 22, 2025
@KoBeWi KoBeWi requested a review from a team as a code owner May 22, 2025 13:09
@KoBeWi KoBeWi requested a review from a team as a code owner May 22, 2025 13:09
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected.

Testing project: test_pr_106717.zip

func _ready() -> void:
	print(ResourceUID.path_to_uid("res://node_2d.tscn"))
	print(ResourceUID.path_to_uid("res://node_2d.gd"))
	print(ResourceUID.path_to_uid("res://notfound"))
	print(ResourceUID.path_to_uid("not_res"))

	print()
	print(ResourceUID.uid_to_path("uid://bamx8gv7ycx3l"))
	print(ResourceUID.uid_to_path("uid://jdo0axvhs6by"))
	print(ResourceUID.path_to_uid("uid://notfound"))
	print(ResourceUID.path_to_uid("not_uid"))

	print()
	print(ResourceUID.ensure_path("res://node_2d.tscn"))
	print(ResourceUID.ensure_path("res://node_2d.gd"))
	print(ResourceUID.ensure_path("res://notfound"))
	print(ResourceUID.ensure_path("not_res"))

	print()
	print(ResourceUID.ensure_path("uid://bamx8gv7ycx3l"))
	print(ResourceUID.ensure_path("uid://jdo0axvhs6by"))
	print(ResourceUID.ensure_path("uid://notfound"))
	print(ResourceUID.ensure_path("not_uid"))

Outputs:

uid://bamx8gv7ycx3l
uid://jdo0axvhs6by
res://notfound
not_res

res://node_2d.tscn
res://node_2d.gd
uid://notfound
not_uid

res://node_2d.tscn
res://node_2d.gd
res://notfound
not_res

res://node_2d.tscn
res://node_2d.gd

not_uid

One interesting difference is that using ensure_path() with res://notfound returns the string as-is, while uid://notfound returns an empty string.

@KoBeWi KoBeWi force-pushed the uid_in_path_factory branch from ceb741c to 9c37ca5 Compare May 24, 2025 22:26
@Repiteo Repiteo merged commit c38b856 into godotengine:master May 26, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented May 26, 2025

Thanks!

@KoBeWi KoBeWi deleted the uid_in_path_factory branch May 26, 2025 16:44
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.

4 participants