From ebee9898ca71a7388412225fccaf460c258c6940 Mon Sep 17 00:00:00 2001 From: Bojidar Marinov Date: Mon, 11 Sep 2017 12:34:36 +0300 Subject: [PATCH] Fix duplication of nodes resulting in shared metadata Fixes #9547 --- editor/scene_tree_dock.cpp | 9 ++++++++- scene/main/node.cpp | 21 +++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index afdf48b3148..4fe24a2eff5 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -823,7 +823,14 @@ Node *SceneTreeDock::_duplicate(Node *p_node, Map &duplimap) { if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; String name = E->get().name; - node->set(name, p_node->get(name)); + Variant value = p_node->get(name); + // Duplicate dictionaries and arrays, mainly needed for __meta__ + if (value.get_type() == Variant::DICTIONARY) { + value = Dictionary(value).copy(); + } else if (value.get_type() == Variant::ARRAY) { + value = Array(value).duplicate(); + } + node->set(name, value); } List group_info; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index c3d9d97c5a9..a543dba9cb9 100755 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2117,7 +2117,15 @@ Node *Node::_duplicate(int p_flags) const { if (!(p_flags & DUPLICATE_SCRIPTS) && name == "script/script") continue; - node->set(name, get(name)); + Variant value = get(name); + // Duplicate dictionaries and arrays, mainly needed for __meta__ + if (value.get_type() == Variant::DICTIONARY) { + value = Dictionary(value).copy(); + } else if (value.get_type() == Variant::ARRAY) { + value = Array(value).duplicate(); + } + + node->set(name, value); } node->set_name(get_name()); @@ -2199,7 +2207,16 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map &p if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; String name = E->get().name; - node->set(name, get(name)); + + Variant value = get(name); + // Duplicate dictionaries and arrays, mainly needed for __meta__ + if (value.get_type() == Variant::DICTIONARY) { + value = Dictionary(value).copy(); + } else if (value.get_type() == Variant::ARRAY) { + value = Array(value).duplicate(); + } + + node->set(name, value); } node->set_name(get_name());