Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shared exported variables of inherited scenes #88741

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion scene/resources/packed_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -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<Resource> res = value;
Expand Down
Loading