Fix shared exported variables of inherited scenes

This commit is contained in:
Adam Scott 2024-02-23 17:00:46 -05:00
parent 3abb32671e
commit d53a1b0e84
No known key found for this signature in database
GPG key ID: 1352C2919D96DDDF

View file

@ -189,6 +189,7 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
Node *node = nullptr; Node *node = nullptr;
MissingNode *missing_node = nullptr; MissingNode *missing_node = nullptr;
bool is_inherited_scene = false;
if (i == 0 && base_scene_idx >= 0) { if (i == 0 && base_scene_idx >= 0) {
// Scene inheritance on root node. // 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) { if (p_edit_state != GEN_EDIT_STATE_DISABLED) {
node->set_scene_inherited_state(sdata->get_state()); node->set_scene_inherited_state(sdata->get_state());
} }
is_inherited_scene = true;
} else if (n.instance >= 0) { } else if (n.instance >= 0) {
// Instance a scene into this node. // Instance a scene into this node.
if (n.instance & FLAG_INSTANCE_IS_PLACEHOLDER) { if (n.instance & FLAG_INSTANCE_IS_PLACEHOLDER) {
@ -344,6 +345,12 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
} else { } else {
Variant value = props[nprops[j].value]; 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) { if (value.get_type() == Variant::OBJECT) {
//handle resources that are local to scene by duplicating them if needed //handle resources that are local to scene by duplicating them if needed
Ref<Resource> res = value; Ref<Resource> res = value;