1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-12 13:20:55 +00:00

Merge pull request #67124 from KoBeWi/load_before_save

Fallback to ResourceLoader if can't find UID
This commit is contained in:
Rémi Verschelde
2022-10-10 17:42:24 +02:00

View File

@@ -2259,7 +2259,7 @@ void EditorFileSystem::move_group_file(const String &p_path, const String &p_new
ResourceUID::ID EditorFileSystem::_resource_saver_get_resource_id_for_path(const String &p_path, bool p_generate) { ResourceUID::ID EditorFileSystem::_resource_saver_get_resource_id_for_path(const String &p_path, bool p_generate) {
if (!p_path.is_resource_file() || p_path.begins_with(ProjectSettings::get_singleton()->get_project_data_path())) { if (!p_path.is_resource_file() || p_path.begins_with(ProjectSettings::get_singleton()->get_project_data_path())) {
//saved externally (configuration file) or internal file, do not assign an ID. // Saved externally (configuration file) or internal file, do not assign an ID.
return ResourceUID::INVALID_ID; return ResourceUID::INVALID_ID;
} }
@@ -2267,15 +2267,21 @@ ResourceUID::ID EditorFileSystem::_resource_saver_get_resource_id_for_path(const
int cpos = -1; int cpos = -1;
if (!singleton->_find_file(p_path, &fs, cpos)) { if (!singleton->_find_file(p_path, &fs, cpos)) {
// Fallback to ResourceLoader if filesystem cache fails (can happen during scanning etc.).
ResourceUID::ID fallback = ResourceLoader::get_resource_uid(p_path);
if (fallback != ResourceUID::INVALID_ID) {
return fallback;
}
if (p_generate) { if (p_generate) {
return ResourceUID::get_singleton()->create_id(); //just create a new one, we will be notified of save anyway and fetch the right UUID at that time, to keep things simple. return ResourceUID::get_singleton()->create_id(); // Just create a new one, we will be notified of save anyway and fetch the right UUID at that time, to keep things simple.
} else { } else {
return ResourceUID::INVALID_ID; return ResourceUID::INVALID_ID;
} }
} else if (fs->files[cpos]->uid != ResourceUID::INVALID_ID) { } else if (fs->files[cpos]->uid != ResourceUID::INVALID_ID) {
return fs->files[cpos]->uid; return fs->files[cpos]->uid;
} else if (p_generate) { } else if (p_generate) {
return ResourceUID::get_singleton()->create_id(); //just create a new one, we will be notified of save anyway and fetch the right UUID at that time, to keep things simple. return ResourceUID::get_singleton()->create_id(); // Just create a new one, we will be notified of save anyway and fetch the right UUID at that time, to keep things simple.
} else { } else {
return ResourceUID::INVALID_ID; return ResourceUID::INVALID_ID;
} }