Merge pull request #88741 from adamscott/fix-shared-variables-of-inherited-scenes-redux

Fix shared exported variables of inherited scenes
This commit is contained in:
Rémi Verschelde 2024-05-07 16:49:20 +02:00
commit 29607924bd
No known key found for this signature in database
GPG Key ID: C3336907360768E1

View File

@ -191,6 +191,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.
@ -201,7 +202,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) {
@ -346,6 +347,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<Resource> res = value;