Class reference
ResourceUID
Inherits Object
A singleton that manages the unique identifiers of all resources within a project.
Description
Resource UIDs (Unique IDentifiers) allow the engine to keep references between resources intact, even if files are renamed or moved. They can be accessed with uid://. ResourceUID keeps track of all registered resource UIDs in a project, generates new UIDs, and converts between their string and integer representations.
Methods
void add_id(int id, String path)
int id, String path)Adds a new UID value which is mapped to the given resource path. Fails with an error if the UID already exists, so be sure to check has_id() beforehand, or use set_id() instead.
int create_id()
int create_id()Generates a random resource UID which is guaranteed to be unique within the list of currently loaded UIDs. In order for this UID to be registered, you must call add_id() or set_id().
int create_id_for_path(String path)
int create_id_for_path(String path)Like create_id(), but the UID is seeded with the provided path and project name. UIDs generated for that path will be always the same within the current project.
String ensure_path(String path_or_uid) static
String ensure_path(String path_or_uid) staticReturns a path, converting path_or_uid if necessary. Prints an error if provided an invalid UID.
String get_id_path(int id) const
String get_id_path(int id) constReturns the path that the given UID value refers to. Fails with an error if the UID does not exist, so be sure to check has_id() beforehand.
bool has_id(int id) const
bool has_id(int id) constReturns whether the given UID value is known to the cache.
String id_to_text(int id) const
String id_to_text(int id) constConverts the given UID to a uid:// string value.
String path_to_uid(String path) static
String path_to_uid(String path) staticConverts the provided resource path to a UID. Returns the unchanged path if it has no associated UID.
void remove_id(int id)
int id)Removes a loaded UID value from the cache. Fails with an error if the UID does not exist, so be sure to check has_id() beforehand.
void set_id(int id, String path)
int id, String path)Updates the resource path of an existing UID. Fails with an error if the UID does not exist, so be sure to check has_id() beforehand, or use add_id() instead.
int text_to_id(String text_id) const
int text_to_id(String text_id) constExtracts the UID value from the given uid:// string.
String uid_to_path(String uid) static
String uid_to_path(String uid) staticConverts the provided uid to a path. Prints an error if the UID is invalid.
Constants
INVALID_ID = -1
The value to use for an invalid UID, for example if the resource could not be loaded. Its text representation is uid://<invalid>.