From af94831ab23978e09dc8ebea314bacaabcf641df Mon Sep 17 00:00:00 2001 From: Mikael Hermansson Date: Wed, 2 Jul 2025 20:10:56 +0200 Subject: [PATCH] Fix typed collections using same reference across scene instances --- scene/resources/packed_scene.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 90c3b76ea6..786b551b89 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -372,33 +372,36 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const { if (value.get_type() == Variant::ARRAY) { Array set_array = value; - value = setup_resources_in_array(set_array, n, resources_local_to_sub_scene, node, snames[nprops[j].name], resources_local_to_scene, i, ret_nodes, p_edit_state); - bool is_get_valid = false; Variant get_value = node->get(snames[nprops[j].name], &is_get_valid); if (is_get_valid && get_value.get_type() == Variant::ARRAY) { Array get_array = get_value; - if (!set_array.is_same_typed(get_array)) { - value = Array(set_array, get_array.get_typed_builtin(), get_array.get_typed_class_name(), get_array.get_typed_script()); + if (set_array.is_same_typed(get_array)) { + set_array = set_array.duplicate(); + } else { + set_array = Array(set_array, get_array.get_typed_builtin(), get_array.get_typed_class_name(), get_array.get_typed_script()); } } + + value = setup_resources_in_array(set_array, n, resources_local_to_sub_scene, node, snames[nprops[j].name], resources_local_to_scene, i, ret_nodes, p_edit_state); } if (value.get_type() == Variant::DICTIONARY) { Dictionary set_dict = value; - value = setup_resources_in_dictionary(set_dict, n, resources_local_to_sub_scene, node, snames[nprops[j].name], resources_local_to_scene, i, ret_nodes, p_edit_state); - bool is_get_valid = false; Variant get_value = node->get(snames[nprops[j].name], &is_get_valid); if (is_get_valid && get_value.get_type() == Variant::DICTIONARY) { Dictionary get_dict = get_value; - if (!set_dict.is_same_typed(get_dict)) { - value = Dictionary(set_dict, get_dict.get_typed_key_builtin(), get_dict.get_typed_key_class_name(), get_dict.get_typed_key_script(), - get_dict.get_typed_value_builtin(), get_dict.get_typed_value_class_name(), get_dict.get_typed_value_script()); + if (set_dict.is_same_typed(get_dict)) { + set_dict = set_dict.duplicate(); + } else { + set_dict = Dictionary(set_dict, get_dict.get_typed_key_builtin(), get_dict.get_typed_key_class_name(), get_dict.get_typed_key_script(), get_dict.get_typed_value_builtin(), get_dict.get_typed_value_class_name(), get_dict.get_typed_value_script()); } } + + value = setup_resources_in_dictionary(set_dict, n, resources_local_to_sub_scene, node, snames[nprops[j].name], resources_local_to_scene, i, ret_nodes, p_edit_state); } bool set_valid = true;