Skip to content
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

Script UID improvements #87418

Open
3 tasks
Tracked by #92907
KoBeWi opened this issue Jan 20, 2024 · 6 comments
Open
3 tasks
Tracked by #92907

Script UID improvements #87418

KoBeWi opened this issue Jan 20, 2024 · 6 comments

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Jan 20, 2024

Tested versions

4.3

System information

Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 (NVIDIA; 30.0.15.1403) - Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 Threads)

Issue description

GDScript has a basic UID support now, but it has some missing features:

  • Allow extending script by its UID (extends "uid://acdc")
  • Allow using script preloaded with UID as a type (const Type = preload("uid://acdc"))
  • Add "Copy Script UID" option to Script Editor, in addition to Copy Script Path
    image

The first two result in an error currently, the last one does not exist (though you can copy UID using FileSystem context menu).

Steps to reproduce

Try using any of the above.

Minimal reproduction project (MRP)

N/A

@dalexeev
Copy link
Member

dalexeev commented Jan 24, 2024

Allow using script preloaded with UID as a type (const Type = preload("uid://acdc"))

Preloading with only a UID is less readable and inconsistent with other resources (it is assumed that UIDs can be safely removed/changed). I would expect an optional uid argument for load/preload:

const Type = preload("res://script.gd", "uid://acdc")

The same for extends, but the syntax probably looks worse due to the lack of parentheses:

extends "res://script.gd", "uid://acdc"

Also note that you can use relative paths with preload and extends:

extends "./script.gd"

const Type = preload("./other_script.gd")

For load, we can also add support for relative paths (see #66550 (comment)) or add "magic" constants like __FILE__, __DIR__ (but we should distinguish between absolute and res:// paths).

@AThousandShips
Copy link
Member

This would also allow us to have a warning if the plain path is out of date, possibly with an option to update it in the editor

@KoBeWi
Copy link
Member Author

KoBeWi commented Jan 24, 2024

Preloading with only a UID is less readable and inconsistent with other resources (it is assumed that UIDs can be safely removed/changed).

No, the whole purpose of UID is that it's not supposed to change, unlike paths. The engine ensures that. Other resources already support load and preload, it only doesn't work for scripts.

The readability can be always improved by adding a tooltip when hovering UID or even displaying it in a special way.

This would also allow us to have a warning if the plain path is out of date, possibly with an option to update it in the editor

That's not any different from what we have now. When you change path, any script referencing it will break. Issuing a warning would require scanning every script on every path change and updating is useless unless it happens automatically. We could implement that even without UIDs.

@AThousandShips
Copy link
Member

I meant with both uid and path, that specific suggestion

@dalexeev
Copy link
Member

The readability can be always improved by adding a tooltip when hovering UID or even displaying it in a special way.

This is only possible for the built-in editor. For external editors, GitHub, etc. this is less convenient (requires plugins or is not possible). When you see extends "uid://lalala" or preload("uid://lalal") you don't know where to look for that file and it's much harder to guess what it does, especially in the case of extends.

No, the whole purpose of UID is that it's not supposed to change, unlike paths. The engine ensures that.

Sometimes Godot changes UIDs for some reason, even if I didn't recreate the resource, but only edited/renamed/moved that resource or its dependencies. I think that in the current implementation this is also possible for GDScript, since the UID line is not only inserted when creating the .gd file, but can also be changed later via the set_uid() method.

So I wouldn't be sure that UID persistence is guaranteed. Also, as far as I understand, UID was not intended to be a replacement for file paths, only a secondary addressing system. All other resources store both file path and UID. The UID may be missing, but the path must be there. This is what I meant by inconsistency.

That's not any different from what we have now. When you change path, any script referencing it will break.

The difference is that if you encounter an incorrect file path (for example, if you got someone else's project), you can try to look for the components of the path in the file system, most often the file can be quickly found. If you encounter an incorrect UID that has no references left along with the file path, then it could be almost any script/resource (if you are not familiar with the project).

@KoBeWi
Copy link
Member Author

KoBeWi commented Jan 24, 2024

This is only possible for the built-in editor. For external editors, GitHub, etc. this is less convenient

External editors have extensions. VS Code extension can e.g. show paths of external resources referenced in the scene:
image
UID display is likely possible too and might be even easier than in the Godot editor, because we don't have script editor extensions.

Sometimes Godot changes UIDs for some reason, even if I didn't recreate the resource

That's a bug.

since the UID line is not only inserted when creating the .gd file, but can also be changed later via the set_uid() method.

The editor should not change UIDs without a reason. IIRC set_uid() specifically was added to fix UID conflicts when duplicating files. User using set_uid() is irrelevant.

If you encounter an incorrect UID that has no references left along with the file path, then it could be almost any script/resource (if you are not familiar with the project).

That's fair I guess. But as I said above, incorrect UIDs are not something expected and AFAIK we have most cases already fixed.

Using UIDs in preloads is currently not supported well, because you need to manually copy the UID. If we add a special syntax for both path/UID, we could automatically insert it when drag and dropping files. But I'd make both path and UID optional, so user could use either of them or both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants