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

ResourceSaver.save deletes UID from resource when not running inside the Editor #83259

Closed
Rubonnek opened this issue Oct 13, 2023 · 5 comments · Fixed by #83388
Closed

ResourceSaver.save deletes UID from resource when not running inside the Editor #83259

Rubonnek opened this issue Oct 13, 2023 · 5 comments · Fixed by #83388

Comments

@Rubonnek
Copy link
Member

Rubonnek commented Oct 13, 2023

Godot version

master branch at ee118e7

System information

Arch Linux

Issue description

ResourceSaver.save removes the UID when present in a resource.

I was expecting it to either keep the current UID or generate a new one.

Steps to reproduce

  1. Open the attached MRP and note that resource_with_uid.tres has an UID:
[gd_resource type="Resource" format=3 uid="uid://cm483l5h4cwi2"]
  1. Run the attached project which will run: ResourceSaver.save(load("res://resource_with_uid.tres"))
  2. The UID is now gone:
[gd_resource type="Resource" format=3]

Minimal reproduction project

ResourceSaverUIDNukeBug.zip

@KoBeWi
Copy link
Member

KoBeWi commented Oct 13, 2023

Works correctly when run inside the editor.

@Rubonnek Rubonnek changed the title ResourceSaver.save deletes UID from resource ResourceSaver.save deletes UID from resource on non-@tool scripts Oct 13, 2023
@Rubonnek Rubonnek changed the title ResourceSaver.save deletes UID from resource on non-@tool scripts ResourceSaver.save deletes UID from resource when not running inside the Editor Oct 13, 2023
@jsjtxietian
Copy link
Contributor

jsjtxietian commented Oct 15, 2023

The uid is set by ResourceUID::ID uid = ResourceSaver::get_resource_id_for_path(local_path, true); which will return -1 as uid when save_get_id_for_path is null. save_get_id_for_path is set in EditorFileSystem's constructor. So it's fine in editor but breaks when running.

@AThousandShips
Copy link
Member

I'm not sure how this should be solved, or even treated, UID is an editor specific feature when assigning, and needs to be in editor to be handled correctly

I think this isn't so much a bug as it is a limitation, the one bug would be IMO that you can edit files in the project from a running project, and that this limitation should be documented or you shouldn't be allowed to modify the files this way

@jsjtxietian
Copy link
Contributor

jsjtxietian commented Oct 15, 2023

IMHO I do agree that we should not edit files (or edit resources) from a running project, tool script is built for that purpose. But the uid loss is a limition as it might make the user confuse. Although I think it still works well because the path is not lost so user can still reference the resource, just the uid is missing.

Also it seems hard to detect this problem as load and save are common operations.

@AThousandShips
Copy link
Member

Yeah, could be done when editing in the res file scope, but I think this is more a documentation thing, unless we can find a clear way to error about this

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

Successfully merging a pull request may close this issue.

4 participants