Repository: godotengine/godot (language: cpp)

Issue:
Godot Editor fails to reimport if `.godot` folder is deleted
### Tested versions

4.4.stable, 4.5.dev

### System information

Godot v4.5.dev.mono  - EndeavourOS  SMP PREEMPT_DYNAMIC Fri, 07 Mar 2025 20:19:00 +0000 on Wayland - X11 display driver, Multi-window, 1 monitor - Vulkan (Mobile) - integrated AMD Radeon Graphics (RADV RENOIR) - AMD Ryzen 7 4800U with Radeon Graphics (16 threads)

### Issue description

Godot editor fails to reimport if `.godot` folder is deleted and the `.godot` folder can't re-gengerated, unless reload the project.

https://github.com/user-attachments/assets/f9ccda48-9cc5-478b-8341-8fec6a063535

### Steps to reproduce

Open a project, delete the `.godot` folder, then godot fails to reimport assets.

### Minimal reproduction project (MRP)

[editor-import-bug.zip](https://github.com/user-attachments/files/19270335/editor-import-bug.zip)
Getting `cannot open/create file` error if `.godot` folder is removed when project is already open
### Godot version

v4.2.dev3.official [013e8e3af]

### System information

Godot v4.2.dev3 - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 6GB (NVIDIA; 31.0.15.3640) - Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz (4 Threads)

### Issue description

If project is open in Godot when the `.godot` folder is removed, you get some errors:

![kuva](https://github.com/godotengine/godot/assets/49998025/b4b5b1f2-072b-4887-b765-3fe064f4643a)

```
editor/import/resource_importer_texture.cpp:334 - Condition "f.is_null()" is true.
Cannot open MD5 file 'res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.md5'.
Cannot create file 'res://.godot/editor/filesystem_cache8'. Check user write permissions.
Cannot create file 'res://.godot/editor/filesystem_update4'. Check user write permissions.
```

This happened to me when I constructed a reproduction project for an issue. The project was still opened when I removed `.godot` folder before zipping the project folder.

It seems that Godot recreates the `.godot` folder structure only when a project is opened. Maybe it could be done also when it is detected that saving files to `.godot` folder fails because the whole folder is missing? If this error happens, error messages ("Check user write permissions") do not help very much as this is not write permission problem. Or if the recreation of `.godot` folder is too complicated at this stage, maybe an error message could instruct reloading the project.

The problem can be solved by reloading the project.


### Steps to reproduce

1. Open any project 
2. Remove project's `.godot` folder 
-> get some errors immediately 
3. Save any *.gd file 
-> get some more errors


### Minimal reproduction project

N/A


Discussion / hints:
I'm not sure it's expected that the editor can recover from having the `.godot` folder deleted while the editor is running, it's pretty destructive

See also:
* https://github.com/godotengine/godot/issues/81199
It probably could at least be detected and fail more elegantly. Popup, back to the Project Manager, automatic restart, what have you.
Might not be trivial to detect, but worth looking into, but would likely just involve crashing the editor or exiting immediately
This isn't really something that we can protect against I think, deleting the `.godot` folder while the engine is running breaks everything and doing so isn't something users are ever expected to do, while it can occur accidentally there's very little we can do to deal with it

How do other software with data like this handle this situation? Is it common for software to handle these kind of breakgages graciously?

We could theoretically add some check to discover if the folder or specific files are deleted, but I'm not sure how complete that would be, and it should probably error out and crash the editor, as there's limited ways in which we can recover from this while the engine is still running, as there's files that are loaded, resources, etc.
If this is a situation from where an easy recovery is not possible, maybe just detect the situation ("oh well, .godot is missing") and display error message that instructs the user to reload the project.
The question is, should it work for specific files, like the uuid cache, resource files loaded, etc., or should it detect the folder itself being deleted, the question is what specific files to listen for, and under what conditions to panic as it were

I think that unless we can ensure that the editor doesn't break in some unpredictable way without the `.godot` folder and therefore breaks files by overwriting them or other things I think it would be safest to just crash the editor immediately
Shouldn't we be able to regenerate it safely? If you blow it away, close the project, and reopen it should work. I deleted while open, then closed it, then deleted it again. Still getting the same error complaining about write permissions. 
`Cannot create file 'res://.godot/editor/filesystem_update4'. Check user write permissions.`
Hi! I got the same error.
![image](https://github.com/godotengine/godot/assets/64596931/f94ab4b5-ac0b-4026-a5f9-7f5eff47fa36)

I was searching for answers or help how to recover the project or make it work;
If I figure it out I might leave more information here.

For me, it complains about these MD5 files I never had heard about. I am a programming beginner so everything seems a little daunting : ' D
From googling, I gathered that these files are some sort of...verification container of specific files.
Now, what's odd is, i copy pasted the imported files over from another folder.
There are scribbles, which uploaded perfectly,

![image](https://github.com/godotengine/godot/assets/64596931/69d6628a-4183-4c8c-a062-77b3a05aa090)

and other images, that throw this error no matter what, including pixel art, .pngs, digital drawings n such.

![image](https://github.com/godotengine/godot/assets/64596931/0f1787a1-fcd6-4ca6-b2dc-03cf40a48a88)
![CHAR  Archivist - Smiling](https://github.com/godotengine/godot/assets/64596931/af3907fb-b8d1-4933-8f9e-1c158fe9e62f)

I tried renaming files, closing and opening the program, deleting and reimporting e v e r y t h i n g, but it does not work.

Now, this project lies in a git folder, I will check if maybe that is the issue?

I did not understand the issue, but I t h i n k I solved it.
Now I can import images I couldn't earlier, and the error did not even pop up anymore when launching.

The solution was to copy the entirety of the project folder out of the folder it was currently in, nuke the folder it was in with fire, and open it from a different place.

Still within the github folder, so it might not have been a github related issue, but was definitely an issue with the folder it was inside. Make sure to make version control/copy your project elsewhere after you made progress, that's always helpful!

> Hi! I got the same error. ![image](https://private-user-images.githubusercontent.com/64596931/344937716-f94ab4b5-ac0b-4026-a5f9-7f5eff47fa36.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5MDkwMDAsIm5iZiI6MTcxOTkwODcwMCwicGF0aCI6Ii82NDU5NjkzMS8zNDQ5Mzc3MTYtZjk0YWI0YjUtYWMwYi00MDI2LWE1ZjktN2Y1ZWZmNDdmYTM2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzAyVDA4MjUwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFiOGY3OTUwNTIwNTc5NWRmZWMxZTljYjBiZTM3NTg4MDJmNDcwYjQ0ZTI3N2JhNTI3YmU3NjU2OWFiMjE0ZDQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.36KBLoM3qWM5DC0CvjPFJHtvp8UBZdG4TwslaZbJV80)
> 
> I was searching for answers or help how to recover the project or make it work; If I figure it out I might leave more information here.
> 
> For me, it complains about these MD5 files I never had heard about. I am a programming beginner so everything seems a little daunting : ' D From googling, I gathered that these files are some sort of...verification container of specific files. Now, what's odd is, i copy pasted the imported files over from another folder. There are scribbles, which uploaded perfectly,
> 
> ![image](https://private-user-images.githubusercontent.com/64596931/344939403-69d6628a-4183-4c8c-a062-77b3a05aa090.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5MDkwMDAsIm5iZiI6MTcxOTkwODcwMCwicGF0aCI6Ii82NDU5NjkzMS8zNDQ5Mzk0MDMtNjlkNjYyOGEtNDE4My00YzhjLWEwNjItNzdiM2EwNWFhMDkwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzAyVDA4MjUwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTcyYjU1YTBmMThmM2IyNmUxN2E3ZGZhODNlNjFhNDcwNTllOTUyNTZmOGYxODE0MGJiMzBjNjJmNjUxZTFhNDAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.54_JBfapOJieBeaPfS5SiWnKZGJ7Ho5XiLFIQmz98i8)
> 
> and other images, that throw this error no matter what, including pixel art, .pngs, digital drawings n such.
> 
> ![image](https://private-user-images.githubusercontent.com/64596931/344939784-0f1787a1-fcd6-4ca6-b2dc-03cf40a48a88.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5MDkwMDAsIm5iZiI6MTcxOTkwODcwMCwicGF0aCI6Ii82NDU5NjkzMS8zNDQ5Mzk3ODQtMGYxNzg3YTEtZmNkNi00Y2E2LWIyZGMtMDNjZjQwYTQ4YTg4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzAyVDA4MjUwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk4YTRiMGRkOGVjYjhkMDhiZGI0ZTIxYmI4YWY5YmEzNjU4OGUzOTc4ODQ0YzNkY2Q0MWI5ZjNjMjdhYmI2MzcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.5grWcEO8vAjNiy7R3KJCYcnCS0TLwg_jenLexcJkYwE) ![CHAR Archivist - Smiling](https://private-user-images.githubusercontent.com/64596931/344939841-af3907fb-b8d1-4933-8f9e-1c158fe9e62f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5MDkwMDAsIm5iZiI6MTcxOTkwODcwMCwicGF0aCI6Ii82NDU5NjkzMS8zNDQ5Mzk4NDEtYWYzOTA3ZmItYjhkMS00OTMzLThmOWUtMWMxNThmZTllNjJmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzAyVDA4MjUwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVhNmUyZjFkNDRhNDU3OTk1ZGRiZWE0ZWM3N2I3ZTk5NGFhYTJjMDU3OWE0YTVhZGZiNmJiYmUyNGY5MGFjZWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.MUvNsN0mBD5Wlijn3Jou1nzbPGbS9EqgDEbqYbqFxKk)
> 
> I tried renaming files, closing and opening the program, deleting and reimporting e v e r y t h i n g, but it does not work.
> 
> Now, this project lies in a git folder, I will check if maybe that is the issue?



Fix patch:
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 0aec3cff8ddd..9cfce9d59834 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -600,6 +600,43 @@ void EditorNode::update_preview_themes(int p_mode) {
 	}
 }
 
+bool EditorNode::_is_project_data_missing() {
+	Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+	const String project_data_dir = EditorPaths::get_singleton()->get_project_data_dir();
+	if (!da->dir_exists(project_data_dir)) {
+		return true;
+	}
+
+	String project_data_gdignore_file_path = project_data_dir.path_join(".gdignore");
+	if (!FileAccess::exists(project_data_gdignore_file_path)) {
+		Ref<FileAccess> f = FileAccess::open(project_data_gdignore_file_path, FileAccess::WRITE);
+		if (f.is_valid()) {
+			f->store_line("");
+		} else {
+			ERR_PRINT("Failed to create file " + project_data_gdignore_file_path.quote() + ".");
+		}
+	}
+
+	String uid_cache = ResourceUID::get_singleton()->get_cache_file();
+	if (!da->file_exists(uid_cache)) {
+		Error err = ResourceUID::get_singleton()->save_to_cache();
+		if (err != OK) {
+			ERR_PRINT("Failed to create file " + uid_cache.quote() + ".");
+		}
+	}
+
+	const String dirs[] = {
+		EditorPaths::get_singleton()->get_project_settings_dir(),
+		ProjectSettings::get_singleton()->get_imported_files_path()
+	};
+	for (const String &dir : dirs) {
+		if (!da->dir_exists(dir)) {
+			return true;
+		}
+	}
+	return false;
+}
+
 void EditorNode::_notification(int p_what) {
 	switch (p_what) {
 		case NOTIFICATION_POSTINITIALIZE: {
@@ -753,7 +790,11 @@ void EditorNode::_notification(int p_what) {
 			// Restore the original FPS cap after focusing back on the editor.
 			OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/low_processor_mode_sleep_usec")));
 
-			EditorFileSystem::get_singleton()->scan_changes();
+			if (_is_project_data_missing()) {
+				project_data_missing->popup_centered();
+			} else {
+				EditorFileSystem::get_singleton()->scan_changes();
+			}
 			_scan_external_changes();
 
 			GDExtensionManager *gdextension_manager = GDExtensionManager::get_singleton();
@@ -7942,6 +7983,13 @@ EditorNode::EditorNode() {
 
 	gui_base->add_child(disk_changed);
 
+	project_data_missing = memnew(ConfirmationDialog);
+	project_data_missing->set_text(TTRC("Project data folder (.godot) is missing. Please restart editor."));
+	project_data_missing->connect(SceneStringName(confirmed), callable_mp(this, &EditorNode::restart_editor).bind(false));
+	project_data_missing->set_ok_button_text(TTRC("Restart"));
+
+	gui_base->add_child(project_data_missing);
+
 	add_editor_plugin(memnew(AnimationPlayerEditorPlugin));
 	add_editor_plugin(memnew(AnimationTrackKeyEditEditorPlugin));
 	add_editor_plugin(memnew(AnimationMarkerKeyEditEditorPlugin));
diff --git a/editor/editor_node.h b/editor/editor_node.h
index a49c24b31a98..346946c49f94 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -411,6 +411,7 @@ class EditorNode : public Node {
 
 	Tree *disk_changed_list = nullptr;
 	ConfirmationDialog *disk_changed = nullptr;
+	ConfirmationDialog *project_data_missing = nullptr;
 
 	bool scene_distraction_free = false;
 	bool script_distraction_free = false;
@@ -670,6 +671,8 @@ class EditorNode : public Node {
 
 	void _execute_upgrades();
 
+	bool _is_project_data_missing();
+
 protected:
 	friend class FileSystemDock;
 


Test patch: