Skip to content

Commit 711ecb5

Browse files
committed
Merge pull request #108816 from Rindbee/save-the-changes-before-duplicating-resource-files
Save the changes before duplicating resource files
2 parents ac15c67 + cfb6dc4 commit 711ecb5

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

editor/file_system/editor_file_system.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,8 +3107,31 @@ Error EditorFileSystem::_copy_file(const String &p_from, const String &p_to) {
31073107
}
31083108
} else {
31093109
// Load the resource and save it again in the new location (this generates a new UID).
3110-
Error err;
3111-
Ref<Resource> res = ResourceLoader::load(p_from, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err);
3110+
Error err = OK;
3111+
Ref<Resource> res = ResourceCache::get_ref(p_from);
3112+
if (res.is_null()) {
3113+
res = ResourceLoader::load(p_from, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err);
3114+
} else {
3115+
bool edited = false;
3116+
List<Ref<Resource>> cached;
3117+
ResourceCache::get_cached_resources(&cached);
3118+
for (Ref<Resource> &resource : cached) {
3119+
if (!resource->is_edited()) {
3120+
continue;
3121+
}
3122+
if (!resource->get_path().begins_with(p_from)) {
3123+
continue;
3124+
}
3125+
// The resource or one of its built-in resources is edited.
3126+
edited = true;
3127+
resource->set_edited(false);
3128+
}
3129+
3130+
if (edited) {
3131+
// Save cached resources to prevent changes from being lost and to prevent discrepancies.
3132+
EditorNode::get_singleton()->save_resource(res);
3133+
}
3134+
}
31123135
if (err == OK && res.is_valid()) {
31133136
err = ResourceSaver::save(res, p_to, ResourceSaver::FLAG_COMPRESS);
31143137
if (err != OK) {

0 commit comments

Comments
 (0)