summaryrefslogtreecommitdiffstats
path: root/scene/resources/packed_scene.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/packed_scene.cpp')
-rw-r--r--scene/resources/packed_scene.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index 94a031947a..0c57c6b7ba 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -32,7 +32,6 @@
#include "core/config/engine.h"
#include "core/config/project_settings.h"
-#include "core/core_string_names.h"
#include "core/io/missing_resource.h"
#include "core/io/resource_loader.h"
#include "core/templates/local_vector.h"
@@ -191,6 +190,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 +201,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) {
@@ -314,6 +314,16 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
ERR_FAIL_INDEX_V(nprops[j].value, prop_count, nullptr);
if (nprops[j].name & FLAG_PATH_PROPERTY_IS_NODE) {
+ if (!Engine::get_singleton()->is_editor_hint() && node->get_scene_instance_load_placeholder()) {
+ // We cannot know if the referenced nodes exist yet, so instead of deferring, we write the NodePaths directly.
+
+ uint32_t name_idx = nprops[j].name & (FLAG_PATH_PROPERTY_IS_NODE - 1);
+ ERR_FAIL_UNSIGNED_INDEX_V(name_idx, (uint32_t)sname_count, nullptr);
+
+ node->set(snames[name_idx], props[nprops[j].value], &valid);
+ continue;
+ }
+
uint32_t name_idx = nprops[j].name & (FLAG_PATH_PROPERTY_IS_NODE - 1);
ERR_FAIL_UNSIGNED_INDEX_V(name_idx, (uint32_t)sname_count, nullptr);
@@ -327,7 +337,7 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
ERR_FAIL_INDEX_V(nprops[j].name, sname_count, nullptr);
- if (snames[nprops[j].name] == CoreStringNames::get_singleton()->_script) {
+ if (snames[nprops[j].name] == CoreStringName(script)) {
//work around to avoid old script variables from disappearing, should be the proper fix to:
//https://github.com/godotengine/godot/issues/2958
@@ -346,6 +356,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;