ResourceUID

Inherits: Object

Singleton for managing a cache of resource UIDs within a project.

Description

Resources can not only be referenced using their resource paths res://, but alternatively through a unique identifier specified via uid://.

Using UIDs allows for the engine to keep references between resources intact, even if the files get renamed or moved.

This singleton is responsible for keeping track of all registered resource UIDs of a project, generating new UIDs and converting between the string and integer representation.

Methods

void

add_id ( int id, String path )

int

create_id ( )

String

get_id_path ( int id ) const

bool

has_id ( int id ) const

String

id_to_text ( int id ) const

void

remove_id ( int id )

void

set_id ( int id, String path )

int

text_to_id ( String text_id ) const

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>.

Method Descriptions

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 ( )

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.


Returns 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.


Returns whether the given UID value is known to the cache.


Converts the given UID to a uid:// string value.


  • void remove_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.


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.


Extracts the UID value from the given uid:// string.