Repository: godotengine/godot
File: editor/docks/scene_tree_dock.cpp (C++)

Code before:
			if (R.value->is_local_to_scene()) {
				R.value->setup_local_to_scene();
			}
		}
	}

	return pasted_nodes;
}

void SceneTreeDock::paste_node_as_replacement() {
	List<Node *> selected_node_list = editor_selection->get_top_selected_node_list();
	for (Node *selected : selected_node_list) {
		Node *clipboard_node = node_clipboard.front()->get();
		HashMap<const Node *, Node *> duplimap;
		Node *new_node = clipboard_node->duplicate_from_editor(duplimap);
		if (!new_node) {
			continue;
		}
		EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
		String old_scene_file_path = selected->get_scene_file_path();
		String new_scene_file_path = clipboard_node->get_scene_file_path();

		bool old_is_scene = !old_scene_file_path.is_empty();
		bool new_is_scene = !new_scene_file_path.is_empty();

		LocalVector<Node *> old_childs;

		ur->create_action(TTR("Paste Node as Replacement"), UndoRedo::MERGE_DISABLE, selected);

		if (old_is_scene) {
			for (int i = 0; i < selected->get_child_count(); i++) {
				Node *child = selected->get_child(i);
				if (child->get_owner() == selected) {
					ur->add_do_method(selected, "remove_child", child);

					selected->remove_child(child);
					old_childs.push_back(child);
				}
			}
		}

		ur->add_do_method(this, "replace_node", selected, new_node, false);
		ur->add_do_method(new_node, "set_scene_file_path", new_scene_file_path);
		ur->add_do_reference(new_node);

		if (new_is_scene) {
			for (int i = 0; i < new_node->get_child_count(); i++) {
				Node *child = new_node->get_child(i);
				if (child->get_owner() == new_node) {
					ur->add_undo_method(new_node, "add_child", child, true);
					ur->add_undo_method(child, "set_owner", new_node);

Review comment (suggestion):
```suggestion
		LocalVector<Node *> old_children;
```

Code after:
		if (node_clipboard.size() == 1) {
			ur->add_do_method(EditorNode::get_singleton(), "push_item", dup);
		}
	}

	ur->commit_action();

	for (KeyValue<Node *, HashMap<Ref<Resource>, Ref<Resource>>> &KV : resources_local_to_scenes) {
		for (KeyValue<Ref<Resource>, Ref<Resource>> &R : KV.value) {
			if (R.value->is_local_to_scene()) {
				R.value->setup_local_to_scene();
			}
		}
	}

	return pasted_nodes;
}

void SceneTreeDock::paste_node_as_replacement() {
	List<Node *> selected_node_list = editor_selection->get_top_selected_node_list();
	for (Node *selected : selected_node_list) {
		Node *clipboard_node = node_clipboard.front()->get();
		HashMap<const Node *, Node *> duplimap;
		Node *new_node = clipboard_node->duplicate_from_editor(duplimap);
		if (!new_node) {
			continue;
		}
		EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
		String old_scene_file_path = selected->get_scene_file_path();
		String new_scene_file_path = clipboard_node->get_scene_file_path();

		bool old_is_scene = !old_scene_file_path.is_empty();
		bool new_is_scene = !new_scene_file_path.is_empty();

		LocalVector<Node *> old_children;

		ur->create_action(TTR("Paste Node(s) as Replacement"), UndoRedo::MERGE_ALL, selected);

		if (old_is_scene) {
			for (int i = 0; i < selected->get_child_count(); i++) {
				Node *child = selected->get_child(i);
				if (child->get_owner() == selected) {
					ur->add_do_method(selected, "remove_child", child);

					selected->remove_child(child);
					old_children.push_back(child);
				}
			}
		}

		ur->add_do_method(this, "replace_node", selected, new_node, false);