Skip to content

Add project setting to disable UIDs and UID caching #7195

Open
godotengine/godot
#81122
@dhoverml

Description

@dhoverml

Describe the project you are working on

Any Godot project.

Describe the problem or limitation you are having in your project

UID caching was introduced with Godot 4.0, and along with it came a number of bugs (these are what are opened as of today, this doesn't include the fixed bugs)

godotengine/godot#62258
godotengine/godot#64330 (related to 68661)
godotengine/godot#67851 (related to 68661)
godotengine/godot#68661
godotengine/godot#68672 (related to 62258)
#7181

I've also ran into issues with UIDs, and considering I don't require its features I've consider disabling them locally. I'm worried about future Godot features that absolutely require UIDs, as well as other unintended side effects.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add a project setting called application/config/enable_uid_cache (or application/config/enable_uids) to enable (default) or disable UIDs and UID caching (uid_cache.bin), plus a description for the pros and cons of doing so.

Pros:

  1. Reduce noise in git since UIDs won't change in scene or resource files, since there are none.
  2. Can be used as a workaround for bugs that a user cannot otherwise workaround, like for the bugs listed earlier.
  3. Reduces one point of confusion when incorrect scenes or resources are loaded, especially for new users.
  4. Saves some space in the final exported project, granted it's not much (usually <100KB; highly dependent on the project).

Cons:

  1. Moving a file can break other scenes/resources outside of the editor.
  2. Existing code that loads UIDs explicitly, like with load("uid://someuid") will break.
  3. 3rd party addons that load UIDs explicitly will also break.

This appears as though Godot would now have to support "UIDs" and "no UID"s, however the code already does this for the most part by checking for ResourceID::INVALID_ID and falling back to paths (or doing nothing, depending on the context).

I've been hesitant on this proposal because I'm pretty sure it's going to be rejected only because UIDs were added to solve the problems (the Cons) above, and could only cause even more confusion (like if a user has UIDs disabled, then adds an addon that uses UIDs and sees it not working).
Though I want to open some discussion on it considering how low-impact the underlying change is, and how easy it is for a user to just switch back to UIDs (by re-enabling this option).

Possible alternative:
A hybrid approach could mitigate some of the Cons (2 and 3) by using existing UIDs, but not generate new UIDs for new scenes/etc. This can be thought of as "locking in" existing UIDs. Empty projects that set this setting will not have UIDs assigned to anything. However if they include an addon that uses UIDs then the addon will still function normally since UID lookup will still work correctly.
This could be considered even more confusing from a user perspective though.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Below describes the original idea, not the hybrid approach.

  1. At initialization in main.cpp, choose either ResourceUID or a new class that derives from ResourceUID (ResourceUIDDummy or ResourceUIDStub) based on whether application/config/enable_uid_cache is true or false.
  2. ResourceUIDDummy deletes uid_cache.bin, and always returns ResourceID::INVALID_ID, empty strings, Error::OK, etc.
  3. So when ResourceUIDDummy is in use, scenes and resources are saved and loaded similar to pre 4.0, as in, based on path rather than UID. There is no longer a UID stored in the scene (tscn) or resource (.import).
  4. UIDs in existing scenes or resources are ignored when loaded, however saving those scenes or resources will erase the UID.
  5. Keep UIDs and UID caching enabled by default since many projects are currently (and usually unknowingly) using them, as well as not break projects that explicitly use them (like load("uid://something")).

I have a potential (and very lightly tested, unsubmitted) PR that implements this.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, this is part of the core.

Is there a reason why this should be core and not an add-on in the asset library?

ResourceUID must be modified, which cannot be done with an addon.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions