Godot Files Constantly Corrupting

Godot Version

v4.2.1

Question

Hello,
I have been using Godot for around a month now but I’m afraid I will have to stop if my problem keeps persisting. Out of the three projects I have tried to work on, all three have had files corrupt at some point. I really enjoy using Godot but I can’t keep trying to rebuild my projects every few days. I’m not looking for ways to get around the corruption, I want to be able to prevent it from happening. It doesn’t really seem like anyone else is have as much of an issue with this so I’m really confused. Maybe I should switch to the older version of Godot? For now I will try looking at other engines until I can solve this problem. If anyone has ideas on what to do then that would be much appreciated.

1 Like

What are you doing that causes corruption? Usually this happens when manually editing the files, but I have seen it happen with some combinations of scripts with class names and switching around their binds in the editor. I am sure there are other reasons, so you have to tell us when it happens so we can figure out what is causing it. It does not happen when using the editor as originally intended, which is why it is important to report these accurately so they can be fixed.

1 Like

I’ve been arranging my files in the Godot editor itself. The corruption seems to happen when I close the program and then open it again. When I import the corrupted files into a new project or rename them, they work perfectly fine. However, once I close the projects that these fixed files are in and then reopen it, they are corrupted. The only thing in the code that I could imagine corrupting the files might be preloading. I also enabled the “editable children” option in the editor on one of my nodes that control the tile maps.

Update: I’ve made a copy of the project and now it’s telling me that the broken scene has broken dependencies instead of just saying that it is corrupt. However, even when I remap the dependencies, it doesn’t work and still shows the message about the scene being invalid/corrupt when I try to open it.

I’ve noticed some issues with corruption when using preload() under certain circumstances. Any chance this is what you’re seeing?

Maybe, I have used preloading in each of these projects. This was usually done to try to access a node in a different scene.

I don’t quite remember the issue I had, but if you try changing all your preload() to load() (just temporarily) to see if that fixes your issues, then that might either help you move forward or rule it out!

I’ve gotten rid of mentions of preloading in my most recent project since it was quite small and now it is fine. What I don’t understand is why it is corrupting because of this. Do I have to just not preload or is there a way to be safer about it? Thanks a lot for the save by the way.

So it was just yesterday, but I kind of forget the issue. I don’t think preload() is flawed, but I think in some circumstances it can lead to circular dependencies. I believe in my case, I had:

  • A script with class_name that had a preload() call as a script variable
  • A static function that called instance() to create one of those variables
  • Something that used that script by name within the same script

I haven’t looked too deeply into it, but I suspected after changing preload() to load() that I was somehow creating a circular dependency. Not quite sure why load() should do any better though.

Preload runs some checks within the editor for compiler guarantees etc. Load just loads a scene at runtime. When the type system fails to determine some kind of reference within the preloaded scene, because it is not yet registered, a chain of failures causes the scene to not be loaded, thus calling it corrupt. This happens when circular dependencies are created by referencing types of script that eventually reference the scene being loaded again. Godot loads scripts one by one, so if one script fails for any reason, anything depending on that script will also fail, later. Script loading is not stopped by errors when loading in the editor. References to scenes that hold other scenes etc are a problem because they can call scripts that require scripts that have not been succesfully loaded. Godot can’t just load every script in every folder because there could be conflicting definitions of classes for legitimate reasons, so it has to load the scripts that are loaded by scenes. It is a cursed ouroboros that happens because godot gives you a lot of power and fredom.

It is quite mandatory for any coding project of meaning to use a Version Control System like git… I just can highly recommend it to you, besides the corruption issue. If a corruption would happen, you would revert that file to its last functioning state in under one minute … then paste your changes in again, step by step and see when it will be corrupted again for example…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.