summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2023-10-13 13:29:47 +0200
committerkobewi <kobewi4e@gmail.com>2023-10-13 13:31:13 +0200
commita5c984412ce5f5526c43800b50c4b1e45a13d161 (patch)
treee90cedef916bbabaf5c0ac32cac0613bd7d02a13
parent51f81e1c88499f04d2ebdcc0be0b34e73f5e90eb (diff)
downloadredot-engine-a5c984412ce5f5526c43800b50c4b1e45a13d161.tar.gz
Don't try updating wrong NodePaths in resources
-rw-r--r--editor/scene_tree_dock.cpp13
-rw-r--r--editor/scene_tree_dock.h2
2 files changed, 10 insertions, 5 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index a38487635f..9d69addc12 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -1635,10 +1635,15 @@ bool SceneTreeDock::_update_node_path(Node *p_root_node, NodePath &r_node_path,
return false;
}
-bool SceneTreeDock::_check_node_path_recursive(Node *p_root_node, Variant &r_variant, HashMap<Node *, NodePath> *p_renames) const {
+bool SceneTreeDock::_check_node_path_recursive(Node *p_root_node, Variant &r_variant, HashMap<Node *, NodePath> *p_renames, bool p_inside_resource) const {
switch (r_variant.get_type()) {
case Variant::NODE_PATH: {
NodePath node_path = r_variant;
+ if (p_inside_resource && !p_root_node->has_node(node_path)) {
+ // Resources may have NodePaths to nodes that aren't on the scene, so skip them.
+ return false;
+ }
+
if (!node_path.is_empty() && _update_node_path(p_root_node, node_path, p_renames)) {
r_variant = node_path;
return true;
@@ -1650,7 +1655,7 @@ bool SceneTreeDock::_check_node_path_recursive(Node *p_root_node, Variant &r_var
bool updated = false;
for (int i = 0; i < a.size(); i++) {
Variant value = a[i];
- if (_check_node_path_recursive(p_root_node, value, p_renames)) {
+ if (_check_node_path_recursive(p_root_node, value, p_renames, p_inside_resource)) {
if (!updated) {
a = a.duplicate(); // Need to duplicate for undo-redo to work.
updated = true;
@@ -1669,7 +1674,7 @@ bool SceneTreeDock::_check_node_path_recursive(Node *p_root_node, Variant &r_var
bool updated = false;
for (int i = 0; i < d.size(); i++) {
Variant value = d.get_value_at_index(i);
- if (_check_node_path_recursive(p_root_node, value, p_renames)) {
+ if (_check_node_path_recursive(p_root_node, value, p_renames, p_inside_resource)) {
if (!updated) {
d = d.duplicate(); // Need to duplicate for undo-redo to work.
updated = true;
@@ -1699,7 +1704,7 @@ bool SceneTreeDock::_check_node_path_recursive(Node *p_root_node, Variant &r_var
String propertyname = E.name;
Variant old_variant = resource->get(propertyname);
Variant updated_variant = old_variant;
- if (_check_node_path_recursive(p_root_node, updated_variant, p_renames)) {
+ if (_check_node_path_recursive(p_root_node, updated_variant, p_renames, true)) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->add_do_property(resource, propertyname, updated_variant);
undo_redo->add_undo_property(resource, propertyname, old_variant);
diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h
index 9c111bce71..3f02d2881d 100644
--- a/editor/scene_tree_dock.h
+++ b/editor/scene_tree_dock.h
@@ -281,7 +281,7 @@ class SceneTreeDock : public VBoxContainer {
static void _update_configuration_warning();
bool _update_node_path(Node *p_root_node, NodePath &r_node_path, HashMap<Node *, NodePath> *p_renames) const;
- bool _check_node_path_recursive(Node *p_root_node, Variant &r_variant, HashMap<Node *, NodePath> *p_renames) const;
+ bool _check_node_path_recursive(Node *p_root_node, Variant &r_variant, HashMap<Node *, NodePath> *p_renames, bool p_inside_resource = false) const;
bool _check_node_recursive(Variant &r_variant, Node *p_node, Node *p_by_node, const String type_hint, String &r_warn_message);
void _replace_node(Node *p_node, Node *p_by_node, bool p_keep_properties = true, bool p_remove_old = true);