-
-
Notifications
You must be signed in to change notification settings - Fork 19.7k
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
"FIle not found" errors after deleting folder containing GDScript file with custom class_name #81867
Comments
Probably related:
Clearing |
Well, yes, and no. The rogue entry in this file seems to be the cause. Deleting the folder does not delete the lines from this cache file, whilst deleting the file removed it properly. However, simply clearing this file out doesn't provide a clean answer as after I do that, other classes which previously did work, now do not - I get "could not find base class" in the editor for a second class I had created. Therefore, it either needs a "refresh" where it traverses everything and builds up the cache again OR the delete folder function just needs to leverage the delete file function. I tried looking for it in the source code, but its way too big for my small brain - I have no idea where it is. For reference, closing and reopening godot does not rebuild it fully, and just opening the .gd files in the editor does not rebuild it. You have to open the .gd script which contains the class_name, make a change, and save it, for the cache to be updated and all errors to go away. |
A simpler solution to fix the issue is to edit the cache file and remove the parts that mention the file(s) that were deleted. This could easily be automated by a script which would remove any entry that references a file which does not exist, however right now I don't have time to write one. Searching and deleting is fast enough, although of course I'm still waiting for a global fix since this should not be required in the first place. In particular: the bug is extremely incompatible with checking out older commits. At first, all seems to go well, but then you come back to the tip of your main branch, and suddenly Godot has lost its mind, thinks all the old classes it added while you were time-traveling are still there. This causes ridiculous issues, for example, suppose on commit X you moved a global class inside another script, making it an inner class. Then one day you checkout a commit before X: Godot updates the cache with the long-gone global class, and that update stays when you check back out commits after X. At which point, if you try to run your project, Godot tells you: 'Class "Foo" hides a global script class.' And then you're stuck, you can't do anything except update the cache file manually to erase Godot's memory again. EDIT: I literally just tested this scenario to check I wasn't wrong, and therefore shot myself in the foot again, since I do have to edit that cache file manually, and that's very annoying. So I think tomorrow morning I'll write a short Python script to read that file, check which paths exist (in folders that don't contain .gdignore files) and which paths don't anymore (or are ignored and therefore invisible to Godot), and then overwrite the cache with the updated data. I'll post it here if anyone's interested. |
OK, I think this could be a fix for it. Unfortunately, I haven't yet fully got a all the tools downloaded and installed and configured to compile this myself to test, but I think the logic and locations for edits could work: In the _update_scan_actions() function of editor/file_system_editor.cpp, there is a CASE statement. I'm not sure if it should be in the case statement or not, but if a loop can be added to traverse down the whole folder tree from the folder being deleted and check if it is a script file and add it to the list with _queue_update_script_class as in the other case, this should (I think) solve the problem. Looking at the case for ItemAction::ACTION_FILE_ADD: there is a similar feature, so I do think this is where it should go. Hopefully, that helps someone find and fix it. Unless I'm completely wrong of course, which is entirely possible. |
While we wait for a definitive fix to this issue, here's my little Python script to clear the cache file of dead entries: |
Hi, I am not sure that it the right topic for my issue, but sounds similarly: What I did:
Error:
Verification
The main_menu UID has been changed only in one file (res://ui/menu_main/main_menu.tscn) from "uid://b7qjqs6a1budn" to "uid://c4w0clxm2ed2d". Solution I made change in the res://main.tscn file to proper UID: From:
To:
After all I close project and reload it with new definitions. Everything start working again properly. In delete case probably You need to remove line similar to:
I hope it help You... |
Not sure if this is related/relevant... What would be great is if the error message could give some clue where it was when the error happens. i.e. What resource or file or whatever was it parsing when the missing reference happened. It would really speed the ability to solve the problem. Right now it's mostly a mystery. |
Did You check the source files in any other text editor? Maybe it is more general problem with UIDs? |
I have searched for refs to that file without success. The next step is a text-search across all project files. |
Try to check the main project file project.godot. It is text file too.... |
Assuming you use git you can do |
Excellent suggestion!
Ooh. I was going to break out find and grep, but if git can help that's cool. Godot Devs: See those two ideas just quoted? Can't the IDE do that for us? |
There are
godot/editor/filesystem_dock.cpp Lines 2440 to 2443 in ee118e7
That is, processing file operations in |
@Rindbee it is solution for both problems? If yes maybe the topic should be change to more general? Could you change it? |
Sadly it is not, changing the scanning method may require more work. The logic in Another thing worth noting is that the change of dependencies between files is done by |
Godot version
4.1.1
System information
Windows 11
Issue description
When a GDScript file with a custom class_name is deleted, the class is also removed from the editor. However, if the folder is deleted (which contained the same GDScript file) the class is seemingly not removed from the editor and when you search for nodes, it tries to open the missing file and reports errors.
Steps to reproduce
class_name someclass
Attempt to open script 'res://example/myscript.gd' resulted in error 'File not found'.
Failed loading resource: res://example/myscript.gd. Make sure resources have been imported by opening the project in the editor at least once.
editor/create_dialog.cpp:241 - Condition "scr.is_null()" is true.
Closing and reopening Godot has no effect. The only way to fix this, is to create the same GDScript file again and delete the file rather that the folder it is in. Deleting the file itself in step 8 results in no errors being reported.
Minimal reproduction project
N/A
The text was updated successfully, but these errors were encountered: