godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.35k stars 20.24k forks source link

Resources saved to file from an imported scene do not save with consistent UIDs #68672

Open jtnicholl opened 1 year ago

jtnicholl commented 1 year ago

Godot version

v4.0.beta.custom_build [98e0d5995]

System information

Fedora 36

Issue description

If "save to file" is enabled for meshes or animations in an imported scene, the saved resources are given a random UID if the file doesn't already exist. This is annoying if you've .gitignored these files, which makes sense to do since they're auto-generated from glTF files. For example, I did so for the vehicle meshes in the Truck Town demo. If you clone this repo right now, opening any of the vehicle scenes gives multiple invalid UID errors because when the mesh .res files are generated they don't get the same UIDs.

I don't know how UIDs work, but I assume the way to fix this would be to remember what UID the resources are saved to in the glTF's .import file? That way it would be generated with the same UID every time.

Steps to reproduce

  1. Save a mesh or animation resource from a scene to a file using the advanced import options
  2. Reference that resource in a scene and save it
  3. Delete the resource and reimport the scene to regenerate it
  4. Open the scene referencing the resource, notice the invalid UID error

Minimal reproduction project

https://github.com/godotengine/godot-demo-projects/tree/4.0-dev/3d/truck_town

TokisanGames commented 1 year ago

Related https://github.com/godotengine/godot/issues/62258

VantaGhost commented 1 year ago

I'm having this problem in 4.1.1 and it's causing me to lose work. Once these warnings have appeared, the next time you open your project, references in resources affected will be missing entirely. This has caused models to go missing, which have to be reassigned in the scenes they were used in, and materials go missing from those models.

The thing costing me the most time is that for some reason, even though I have external materials (not from the .glb file), those that are referenced in the .glb as "use external" are affected by this issue as well. They lose their reference to the shader they were using, causing all the parameters for that material to be removed, so I have to reconfigure everything on top of reassigning the reference.

This issue seems to be intermittent or at least somewhat random, I had time where it didn't happen, but now it is happening frequently enough to halt development of 3D assets until this bug is resolved. It happens on some models/materials and not on others, there doesn't seem to be a common factor between instances.

Is there a reason this issue is not assigned to a milestone? I know there are other people affected by this issue, here and on the Godot forums. And it seems to have been around in some form on older versions too.

jtnicholl commented 1 year ago

I'm having this problem in 4.1.1 and it's causing me to lose work. Once these warnings have appeared, the next time you open your project, references in resources affected will be missing entirely. This has caused models to go missing, which have to be reassigned in the scenes they were used in, and materials go missing from those models.

I noticed something similar, but I couldn't figure out how to reproduce it so I didn't open a separate issue. What was happening in my case was that the meshes were being saved with the same exact UID as the imported scene. So when loading scenes or resources referencing the mesh, it would try to load the scene they came from instead. But you can't assign a PackedScene to a property that expects a Mesh, so it just assigned null without any errors. To fix it, I removed the line from the .import file that stored the UID, then deleted the mesh files, then reimported.

VantaGhost commented 1 year ago

This sounds like a bug that could cause some pretty severe (but possibly rare) problems. I also noticed that when I tried to use the dependency menu to point towards the right resource instead, setting it just did nothing, but that would make sense if the UID's were the same.

I did find that deleting the mesh imports and re-importing the .glb fixed those temporarily. But it seemed to come back quickly. I didn't try deleting the line from the .import file, is that the one for the .glb? Unfortunately, this "fix" won't work for my broken materials, as they are not imported from the .glb. I still don't know why those are being broken in the same way, it has to be because of the UID overlap, I'm just not sure what it was overlapping with. I think I remember the shader reference pointing towards the .glb or a mesh or something else, but the shader is completely separate to the imported .glb.

Not sure what we are supposed to do with the invalid UID warning, as it seems to be able to fallback to the text path, but not allow us to fix the UID's.

betalars commented 8 months ago

This sounds like a bug that could cause some pretty severe (but possibly rare) problems.

@VentaGhost I can confirm this. Right now I pretty much cannot properly use git with my project because the .res files will have tons of diffs and it is really bad. If I had any back-end knowledge, I'd immediately go fix it myself, but I do not. :c

VantaGhost commented 8 months ago

@betalars So this issue is still happening in the latest version? I had hoped some of the UID changes that came with 4.2 would fix this. Is this with an existing project from before 4.2 or with a new project created with 4.2? Because I wonder if it's just an issue with your project files. Still very unfortunate there isn't a way to fix this, this bug has basically killed that project I was working on because it kept resetting my materials. Might try importing everything to a fresh project at some point but I'd rather not waste time if the bug still exists. By any chance are you working on Linux? Because I'd expect more people to have experienced this bug especially with large projects unless it's platform specific?

betalars commented 7 months ago

@VantaGhost there still seems to be an issue, as demonstrated in this demo project when initialising a new Project in Godot 4.2

In the last commit, something about the res file changes.

Steps to "reproduce":

  1. git clone git@github.com:betalars/godot-uuid-bug.git
  2. open the project in godot
  3. git diff

However, I think this is actually a new issue, as the UUID included in the scene seems to be consistent.

How I forced this error to happen on my side:

  1. I initialised the Repo
  2. Added a Suzanne res, umported it to the main scene
  3. git commit
  4. closed godot
  5. deleted .godot
  6. re-opend godot
  7. suddenly: a diff

@AThousandShips can you try to look into this? I think the issue I've opened before may be it's own problem.

I use nixos as an OS

AThousandShips commented 7 months ago

Unable to do so right now, someone else might be able to look into it

betalars commented 7 months ago

Update: it is a known issue