Skip to content

Commit 6d8469d

Browse files
committed
Merge pull request #108216 from mihe/shared-typed-collections
Fix typed collections using same reference across scene instances
2 parents dcd5893 + af94831 commit 6d8469d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

scene/resources/packed_scene.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,33 +372,36 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
372372

373373
if (value.get_type() == Variant::ARRAY) {
374374
Array set_array = value;
375-
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);
376-
377375
bool is_get_valid = false;
378376
Variant get_value = node->get(snames[nprops[j].name], &is_get_valid);
379377

380378
if (is_get_valid && get_value.get_type() == Variant::ARRAY) {
381379
Array get_array = get_value;
382-
if (!set_array.is_same_typed(get_array)) {
383-
value = Array(set_array, get_array.get_typed_builtin(), get_array.get_typed_class_name(), get_array.get_typed_script());
380+
if (set_array.is_same_typed(get_array)) {
381+
set_array = set_array.duplicate();
382+
} else {
383+
set_array = Array(set_array, get_array.get_typed_builtin(), get_array.get_typed_class_name(), get_array.get_typed_script());
384384
}
385385
}
386+
387+
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);
386388
}
387389

388390
if (value.get_type() == Variant::DICTIONARY) {
389391
Dictionary set_dict = value;
390-
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);
391-
392392
bool is_get_valid = false;
393393
Variant get_value = node->get(snames[nprops[j].name], &is_get_valid);
394394

395395
if (is_get_valid && get_value.get_type() == Variant::DICTIONARY) {
396396
Dictionary get_dict = get_value;
397-
if (!set_dict.is_same_typed(get_dict)) {
398-
value = Dictionary(set_dict, get_dict.get_typed_key_builtin(), get_dict.get_typed_key_class_name(), get_dict.get_typed_key_script(),
399-
get_dict.get_typed_value_builtin(), get_dict.get_typed_value_class_name(), get_dict.get_typed_value_script());
397+
if (set_dict.is_same_typed(get_dict)) {
398+
set_dict = set_dict.duplicate();
399+
} else {
400+
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());
400401
}
401402
}
403+
404+
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);
402405
}
403406

404407
bool set_valid = true;

0 commit comments

Comments
 (0)