From d53a1b0e84f7d764ccb4751ebaa733970ae27122 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Fri, 23 Feb 2024 17:00:46 -0500 Subject: [PATCH] Fix shared exported variables of inherited scenes --- scene/resources/packed_scene.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index a59ac9b56d..5688c1c9ee 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -189,6 +189,7 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const { Node *node = nullptr; MissingNode *missing_node = nullptr; + bool is_inherited_scene = false; if (i == 0 && base_scene_idx >= 0) { // Scene inheritance on root node. @@ -199,7 +200,7 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const { if (p_edit_state != GEN_EDIT_STATE_DISABLED) { node->set_scene_inherited_state(sdata->get_state()); } - + is_inherited_scene = true; } else if (n.instance >= 0) { // Instance a scene into this node. if (n.instance & FLAG_INSTANCE_IS_PLACEHOLDER) { @@ -344,6 +345,12 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const { } else { Variant value = props[nprops[j].value]; + // Making sure that instances of inherited scenes don't share the same + // reference between them. + if (is_inherited_scene) { + value = value.duplicate(true); + } + if (value.get_type() == Variant::OBJECT) { //handle resources that are local to scene by duplicating them if needed Ref res = value;