Browse Source

Fix Resource doesn't update when overwritten in editor

LuoZhihao 2 months ago
parent
commit
0c74c0978f
2 changed files with 11 additions and 6 deletions
  1. 7 1
      editor/editor_node.cpp
  2. 4 5
      editor/gui/editor_quick_open_dialog.cpp

+ 7 - 1
editor/editor_node.cpp

@@ -1585,7 +1585,13 @@ void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const St
 		return;
 	}
 
-	((Resource *)p_resource.ptr())->set_path(path);
+	Ref<Resource> prev_resource = ResourceCache::get_ref(p_path);
+	if (prev_resource.is_null() || prev_resource != p_resource) {
+		p_resource->set_path(path, true);
+	}
+	if (prev_resource.is_valid() && prev_resource != p_resource) {
+		replace_resources_in_scenes({ prev_resource }, { p_resource });
+	}
 	saving_resources_in_path.erase(p_resource);
 
 	_resource_saved(p_resource, path);

+ 4 - 5
editor/gui/editor_quick_open_dialog.cpp

@@ -525,15 +525,14 @@ void QuickOpenResultContainer::_use_default_candidates() {
 	if (history) {
 		candidates.append_array(*history);
 	}
-	int count = candidates.size();
 	candidates.resize(MIN(max_total_results, filepaths.size()));
+	int count = candidates.size();
+	int i = 0;
 	for (const String &filepath : filepaths) {
-		if (count >= max_total_results) {
+		if (i >= count) {
 			break;
 		}
-		if (!history || !history_set.has(filepath)) {
-			_setup_candidate(candidates.write[count++], filepath);
-		}
+		_setup_candidate(candidates.write[i++], filepath);
 	}
 }