-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Open
Labels
area:manualIssues and PRs related to the Manual/Tutorials section of the documentationIssues and PRs related to the Manual/Tutorials section of the documentationcontent:new pageIssues and PRs related to creation of new documentation pages for new or undocumented featuresIssues and PRs related to creation of new documentation pages for new or undocumented featuresenhancement
Description
Your Godot version:
4.5
Issue description:
Godot has UIDs since 4.0, but many users still don't know about them or don't know how to use them correctly. It's especially clear when you look at the comments over in godotengine/godot-proposals#11574
UIDs are unique identifiers associated with Resources. They are like paths, except they never change after the Resource's creation. UIDs can be used instead of paths pretty much everywhere (load()
, preload()
, extends
, @export_file
etc.), the engine uses them internally instead of or in addition to paths. If a Resource is referenced by UID, it can:
- Be moved externally to anywhere in the project.
- It can be moved to anywhere in another project, in which case the dependencies will be automatically resolved to new paths.
When a Resource is referenced by UID, you don't need to worry that its path changes, as the engine is able to find it everywhere.
To properly move a file with UID:
- Move the base file.
- Move the associated file if it exists, that is
.import
or.uid
(e.g.Icon.png.import
,Player.gd.uid
). They both need to land in the same directory. - Note that scenes and resources use both path and UID when referencing dependencies. After moving a file, you may see a warning and/or diffs in files that referenced it. They will be gone after saving affected scene/resource.
Mistakes when handling UID:
- Copying the file externally. When you copy a scene or resource externally into the same project, it will have duplicate UID. This will result in warnings about duplicate UIDs; the engine is able to resolve it if you save the resource inside Godot, but when unnoticed, it can cause bugs in your project.
- When a file has duplicate UID, a common bug is that a scene may load a different dependency than expected. In worst cases, it will look differently in editor than in game.
- Exception to this rule are files with "external" UIDs. If you have an imported resource or a script, you can copy it and omit its associated
.import
or.uid
file. The new resource will receive a new UID automatically. - To avoid problems, copy your files inside the engine. The editor will automatically assign new UID when duplicating files in FileSystem.
- Moving files without their
.import
or.uid
associated files. This will cause the file to receive a new UID, causing problems with dependencies. The engine is able to resolve that, but it should be avoided. - Not committing
.import
or.uid
files to version control. This is similar to the above in that other team members who pull the new files will generate new UIDs for the files.- This will cause warnings that UID can't be found and path is used instead.
Other notes:
- UIDs have both text and numeric representation. The text one is referred to "UID", while the numeric one is usually called "ID". You can convert between them with ResourceUID singleton, but this is rarely needed with normal usage. More common is conversion between path <=> UID.
@export_file
annotation references files by their UID when available (only for Resources).
AThousandShips, coppolaemilio, rburing and AdriaandeJongh
Metadata
Metadata
Assignees
Labels
area:manualIssues and PRs related to the Manual/Tutorials section of the documentationIssues and PRs related to the Manual/Tutorials section of the documentationcontent:new pageIssues and PRs related to creation of new documentation pages for new or undocumented featuresIssues and PRs related to creation of new documentation pages for new or undocumented featuresenhancement