-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Expose path properties save UID internally if referencing a resource #97912
Conversation
1d6067e
to
ea22cdb
Compare
Currently, if a user or some resource exposes a path in a script, if this references a resource path it will be saved as a full path. This will make refactoring not work if the resource pointed towards changes location or is renamed. This change makes it so an uid:// path is saved internally in case a path to a resource has been selected, effectively making it refactor proof.
ea22cdb
to
db25c8f
Compare
This would also make it so that UID paths are always edited as res:// file paths in the inspector, right? Like, if somebody already used a UID path before, it would no longer display that way using this PR |
Yes, but why would you want to see UID in the inspector? |
String EditorPropertyPath::_get_path_text() { | ||
String full_path = get_edited_property_value(); | ||
if (full_path.begins_with("uid://")) { | ||
full_path = ResourceUID::get_singleton()->get_id_path(ResourceUID::get_singleton()->text_to_id(full_path)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to
full_path = ResourceUID::get_singleton()->get_id_path(ResourceUID::get_singleton()->text_to_id(full_path)); | |
return ResourceUID::get_singleton()->get_id_path(ResourceUID::get_singleton()->text_to_id(full_path)); |
and you can make full_path
const.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was about to amend those changes in but I'm not convinced this improves the code quality much. I quite like the pattern where we have a single return
statement at the end and just do conditional changes to the return value.
I certainly don't, but it's something that should be noted. Also, while it should probably be enabled by default, I think that this feature itself should be configurable on a per-project basis. Some people might just prefer to store the file paths instead of UIDs. There are also scenarios where UIDs aren't optimal (eg. replacing a broken scene, the user expects references to stay valid because the filename is the same but suddenly they're broken). One more thing: should the inspector support resource previews this way? Like, an editor setting that (visibly) replaces the file path with the existing resource property GUI if it points to a valid resource, or something like that... Maybe that makes more sense for a different PR, but given that this PR already ties file paths and resource references more closely, it might make sense to follow it up with something like that |
I've thought about this a little bit, and adding a new property hint and associated annotation (eg. Still, say that modifying, using the base directory, file name, file extension, or whatever else from those paths weren't an issue... As stated previously, a custom property hint would cleanly allow for behavior more befitting of the feature, like the ability to use a similar GUI to the one used for (I am willing to take a stab at this feature if all sounds good.) |
The new behavior only applies to files in res:// and only with UID. How does that break your module? |
Because the files are under |
But the property is still accessed as path, it's only stored as UID. And even if it was UID-only, it's easy to retrieve the path from UID. |
Thanks! |
This functionality is totally obfuscated, though. This leads to serious headaches, as most developers will have no idea that this conversion even occurs because the file path is displayed normally in the editor; furthermore, having to handle cases where converting from a UID only might be necessary is just needless hassle. |
tscn/tres support comments. If users will really get confused, we could annotate the property with the corresponding path (though currently there is no support for that). I doubt it will be necessary though, most users will at most see these properties in git diffs and won't really think about it. |
It's more so code that deals with file paths that I was referring to. Sure, I'm familiar with this change, and know to account for it, but as you said, most users won't think about it. This includes tool developers. Unless this behavior is very clearly documented, it will cause confusion. And... if the user isn't meant to think about it, then shouting warnings about it is a bit silly. |
Regression found: #99116 |
Well, a similar thing is happening with
Is it reported? |
@caimantilla The plan is the move the whole engine gradually to UIDs and deprecate paths. I know its an annoyance, but the fact that refactoring basically does not work with paths is a much bigger annoyance and makes it hard to use the engine for bigger projects. |
@KoBeWi the problem with adding a comment is that, if you refactor, the comment will be wrong and will not be renamed. |
But what about leaving @export_file as is and adding something like #91815 and encouraging using that instead? It also provides useful inspector widget |
@Summersay415 The problem is that we've seen many cases of users doing this, assigning a lot of paths, then then being super frustrated when refactoring because they don't get updated. By the time they realize they needed a special annotation its too late, so this behavior should happen by default. The idea is that, by philosophy, paths should not be stored anywhere in future engine versions. |
This looks like topic for more wide discussion, I think. |
@Summersay415 We discussed this for hours at the Sprint in Berlin, and the conclusion was this. Benefits outweight drawbacks. |
Okay, then #91815 is Godot 5 material? |
@Summersay415 No idea, to my awareness there isn't any formal discussion on Godot 5 at the moment. |
If this is the case, then directories should also have UIDs, which would be used by |
@reduz i tried the feature, but i faced the problem that the path does not update, even when you rename or move the file it keeps showing the same path |
Currently, if a user or some resource exposes a path in a script, if this references a resource path it will be saved as a full path.
This will make refactoring not work if the resource pointed towards changes location or is renamed.
This change makes it so an uid:// path is saved internally in case a path to a resource has been selected, effectively making it refactor proof.
Screenshots:
Property is edited as a path:
![image](https://private-user-images.githubusercontent.com/6265307/374194350-b25f792e-3787-4229-bf88-7ae9ad69e36a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4OTgzMDksIm5iZiI6MTczODg5ODAwOSwicGF0aCI6Ii82MjY1MzA3LzM3NDE5NDM1MC1iMjVmNzkyZS0zNzg3LTQyMjktYmY4OC03YWU5YWQ2OWUzNmEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDdUMDMxMzI5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTg3ZTk1YmQ4MzY0ZDQyYmNhY2QzZDNjZmIyYzYzODk4N2FjNTNmNDRkMjgwMjQ4YzdiOTk1MWQ0N2M5MTgxOCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.VWXPlHVgbESlOZp2s1V7NDMaGnIFApLhVmrL3OxYOs0)
![image](https://private-user-images.githubusercontent.com/6265307/374193833-14703645-fb30-4fc7-ba8b-060bd1326a5e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4OTgzMDksIm5iZiI6MTczODg5ODAwOSwicGF0aCI6Ii82MjY1MzA3LzM3NDE5MzgzMy0xNDcwMzY0NS1mYjMwLTRmYzctYmE4Yi0wNjBiZDEzMjZhNWUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDdUMDMxMzI5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NWY4YmMxOTVjZjU1MTJlZDcwODdhNzA5YmI4NGI4NzMwYWFhZTU4ZDA3YmZhZjlmMzE2NjgzYTg3ZTczMGYwZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.jZ5ctikHRNVi-dpUXultr53HG4wiT20ES46ZVSFeWOk)
But value is saved as UID if a resource.
Fixes #97931