diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-03-13 11:00:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-13 11:00:58 +0100 |
commit | 0f429f8f9eb2c2446957b4a97a06b67e616c9d43 (patch) | |
tree | f8ceb5b0539f424c83bc7358d78557ccb75db9cc /scene/resources | |
parent | c46004c5a343fbc5256af7df0d52ed52cf7721ca (diff) | |
parent | 383dea5796d791c89678fe1aea384d42e9f3de8d (diff) |
Merge pull request #7979 from RandomShaper/fix-sub-inheritance
Fix node duplication in scene sub-inheritance
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/packed_scene.cpp | 25 | ||||
-rw-r--r-- | scene/resources/packed_scene.h | 2 |
2 files changed, 21 insertions, 6 deletions
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 0c2f07aa4a..e46d9db7bc 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -995,12 +995,12 @@ int SceneState::find_node_by_path(const NodePath &p_node) const { if (_get_base_scene_state().is_valid()) { int idx = _get_base_scene_state()->find_node_by_path(p_node); if (idx >= 0) { - if (!base_scene_node_remap.has(idx)) { - int ridx = nodes.size() + base_scene_node_remap.size(); - base_scene_node_remap[ridx] = idx; + int rkey = _find_base_scene_node_remap_key(idx); + if (rkey == -1) { + rkey = nodes.size() + base_scene_node_remap.size(); + base_scene_node_remap[rkey] = idx; } - - return base_scene_node_remap[idx]; + return rkey; } } return -1; @@ -1013,11 +1013,24 @@ int SceneState::find_node_by_path(const NodePath &p_node) const { //the node in the instanced scene, as a property may be missing //from the local one int idx = _get_base_scene_state()->find_node_by_path(p_node); - base_scene_node_remap[nid] = idx; + if (idx != -1) { + base_scene_node_remap[nid] = idx; + } } return nid; } + +int SceneState::_find_base_scene_node_remap_key(int p_idx) const { + + for (Map<int, int>::Element *E = base_scene_node_remap.front(); E; E = E->next()) { + if (E->value() == p_idx) { + return E->key(); + } + } + return -1; +} + Variant SceneState::get_property_value(int p_node, const StringName &p_property, bool &found) const { found = false; diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h index 5fa54413a8..b0e89205cb 100644 --- a/scene/resources/packed_scene.h +++ b/scene/resources/packed_scene.h @@ -100,6 +100,8 @@ class SceneState : public Reference { PoolVector<String> _get_node_groups(int p_idx) const; + int _find_base_scene_node_remap_key(int p_idx) const; + protected: static void _bind_methods(); |