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

Moving or renaming scenes in the editor or changing properties in custom resources causes scene corruption #84981

Closed
Tracked by #85081
badihaki opened this issue Nov 16, 2023 · 6 comments · Fixed by #85501

Comments

@badihaki
Copy link

badihaki commented Nov 16, 2023

Godot version

4.2.beta4

System information

Windows 11, AMD Ryzen 5 3600, RTX 2060

Issue description

The Godot engine will lose references to scenes UID cache, causing scenes to register as corrupted. Animations will still work and overall functionality will be retained, but the user loses the ability to open the corrupted scenes. The console will show the below error code. Because scene functionality will be preserved, I believe this has to do with how Godot handles the UID caching of scenes with custom resources

Screenshot 2023-11-06 003745

Steps to reproduce

This can happen when removing/renaming files whether inside or outside the Godot editor (more common outside the editor). It can also happen if you change, rename or delete properties from custom resources.

  • Create a custom resource, add some properties
  • Create a script that exports a variable of type custom resource
  • Create a scene that uses that script. Assign an instance of the custom resource to the script
  • Delete a property from custom resource script
  • Move the scene in either the Godot editor or Explorer
  • OR -
  • Save the script, not the scene

Minimal reproduction project

N/A

@KoBeWi
Copy link
Member

KoBeWi commented Nov 16, 2023

Can't reproduce, please attach a minimal project from right before the scene gets corrupted.
Also be sure to try the newest beta.

@badihaki
Copy link
Author

proj.zip

I believe this should work. Please let me know. I deleted the .godot folder as instructed as well as the addons folder in order to make sure I meet GitHub's requirements. The 'player.tscn', 'dev_room.tscn' and 'spell_container.tscn' scenes all are corrupted, and opening them causes the error shown to be logged.

@KoBeWi
Copy link
Member

KoBeWi commented Nov 18, 2023

I know that might be happening here.
This line:

@export var spell_container_template:PackedScene = preload("res://Content/Cards/Spells/spell_container.tscn")

Preload is known to corrupt resource cache in various ways. I think spell_container.tscn fails to load for some reason (e.g. missing resource or something), causing the scene state to contain no nodes. Then when you try to open the scene, it's not loaded from disk, rather it's using the broken cached version. Restarting the editor seems to fix it.

EDIT:
Opening spell_container.tscn fixes the corruption of the scenes that use it (player.tscn and consequently dev_room.tscn). However you can't open it until #84167 is merged.

We should also improve the errors, because it's not possible to determine which scene failed to load without doing C++ debugging.

Also since (I assume) the scene corruption originally happened due to a moved class, #85037 will help preventing such issues.

@lostminds
Copy link

Then when you try to open the scene, it's not loaded from disk, rather it's using the broken cached version. Restarting the editor seems to fix it.

I ran into a similar issue that might have been caused by this. After moving/renaming some scenes or scripts in 4.2b5 (or6?) one of my scenes got corrupted and would not open in the editor, even after I reverted all the file changes and moves using git (so all files on disk were back to their pre-change state).

Restarting the editor didn't fix it, but running the game did, which felt unexpected. For cases like where it seems that the cache is corrupted (and the engine can tell this, since it's showing you an error), couldn't it just try to re-load the scene from disk once and see if that fixes it? In my case I think this is what happened, but I had to run the game to get it to reload the file cache since it wouldn't do it on open or restart of the editor.

@nulflux
Copy link

nulflux commented Nov 22, 2023

For what it's worth when a scene becomes corrupt and won't open due to this error:

  1. Right-click the corrupt scene in Godot and click Show in File Manager
  2. Rename the scene from 'main.tscn' to 'main1.tscn' where 'main' is the name of the corrupt scene.
  3. Tab back into Godot and double-click the corrupt scene. Now it opens.

@noidexe
Copy link
Contributor

noidexe commented Feb 6, 2024

I have another example:

Here's what the exported variable looks like script looks like

@export var action_list : Array[CombatAction] = []

And here's what it looks like in a saved scene using that script

action_list = Array[Resource("res://scenes/combat/actions/combat_action.gd")]([ExtResource("3_17dhw"), ExtResource("4_scp8g"), ExtResource("3_meexk")])

The script defining the custom resource is only defined by path, and if I move/rename the script Godot won't update the path in the scenes that depend on it. The scene parser seems to fail on errors (not complaining) so in the end you get a supposedly corrupted scene which is actually just a scene with a missing path update

BTW restarting the editor doesn't fix this. You need to manually edit the affected tscn files and only then restart the editor

I think here's the problem:

void ResourceLoaderText::get_dependencies(Ref<FileAccess> p_f, List<String> *p_dependencies, bool p_add_types) {

get_dependencies only handles ext_resources so it will miss any Resource("res://path/to/resource.gd") on exported properties.

@akien-mga akien-mga added this to the 4.3 milestone Feb 24, 2024
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.

8 participants