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

NodePath properly updated in the editor in more cases when nodes are moved or renamed #49812

Merged
merged 1 commit into from
Jun 29, 2021

Conversation

pouleyKetchoupp
Copy link
Contributor

Fix more cases of node path needing an update when nodes are renamed or moved in the editor.

Built-in node properties:
Before, node paths were checked only for script export variables. Now all properties are checked from the node, which includes built-in node properties.
Allows proper node path updates for nodes like remote transform, physics joints, etc.

Arrays and dictionaries:
Node paths nested in array and dictionary properties are now also updated in the editor.

Also update the documentation to be clear about node path update in the editor and at runtime.

Fixes #49810
Fixes #49811

Credits to @latorril for finding the issue and investigating the cause.

@pouleyKetchoupp pouleyKetchoupp added bug topic:core topic:editor cherrypick:3.x Considered for cherry-picking into a future 3.x release labels Jun 21, 2021
@pouleyKetchoupp pouleyKetchoupp added this to the 4.0 milestone Jun 21, 2021
@pouleyKetchoupp pouleyKetchoupp requested review from a team as code owners June 21, 2021 19:22
@pouleyKetchoupp pouleyKetchoupp force-pushed the node-path-editor-update branch 3 times, most recently from f053721 to 9827a3c Compare June 23, 2021 23:40
@pouleyKetchoupp
Copy link
Contributor Author

Pushed a fix for errors in AnimationPlayer due to gathering all properties for checking node paths. Now only properties marked as editor or storage are checked.

Fix more cases of node path needing an update when nodes are renamed or
moved in the editor.

Built-in node properties:
Before, node paths were checked only for script export variables. Now
all properties are checked from the node, which includes built-in node
properties.
Allows proper node path updates for nodes like remote transform, physics
joints, etc.

Arrays and dictionaries:
Node paths nested in array and dictionary properties are now also
updated in the editor.

Also update the documentation to be clear about node path update in the
editor and at runtime.

Co-authored-by: latorril <latorril@gmail.com>
@pouleyKetchoupp pouleyKetchoupp force-pushed the node-path-editor-update branch from 9827a3c to 3e4e530 Compare June 28, 2021 16:28

// Update the node itself if it has a valid node path and has not been deleted.
if (p_root_path == F->get().first && p_node_path != NodePath() && F->get().second != NodePath()) {
NodePath abs_path = NodePath(String(root_path_new).plus_file(p_node_path)).simplified();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed an extra fix here that fixes errors when moving a Skeleton node with BoneAttachment nodes as its children.

Building the new path now uses root_path_new instead of p_root_path, otherwise in cases where the root path and the child path change, this code would generate a buggy node path relative to the old root.

@akien-mga akien-mga merged commit dfdde2c into godotengine:master Jun 29, 2021
@akien-mga
Copy link
Member

Thanks!

Comment on lines +250 to +251
static bool _update_node_path(const NodePath &p_root_path, NodePath &p_node_path, List<Pair<NodePath, NodePath>> *p_renames);
static bool _check_node_path_recursive(const NodePath &p_root_path, Variant &p_variant, List<Pair<NodePath, NodePath>> *p_renames);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just wondering, do those actually need to be static?

Also, since p_node_path and p_variant are used to return new values, they should probably be named with a r_ prefix instead (our convention for a mutable reference that will get changed by the method).

Copy link
Contributor Author

@pouleyKetchoupp pouleyKetchoupp Jun 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't have to be static but they can. I generally set methods as static when possible to make it clear they don't use anything from the class. Do we have a different rule about when to use static?

Makes sense for the missing r_, prefix, I can make a fixup PR to change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't have to be static but they can. I generally set methods as static when possible to make it clear they don't use anything from the class. Do we have a different rule about when to use static?

I don't think we have a specific rule, I'm just asking out of curiosity (and lack of expertise on the actual impact of making things static in C++). If it doesn't hurt and makes the code clearer, that's fine with me :)

@pouleyKetchoupp pouleyKetchoupp deleted the node-path-editor-update branch June 29, 2021 15:36
@akien-mga
Copy link
Member

Cherry-picked for 3.4.

@Flavelius
Copy link
Contributor

Flavelius commented Jul 27, 2021

Does this fix InstancePlaceHolders too by any chance (#44720 (comment))?

@pouleyKetchoupp
Copy link
Contributor Author

@Flavelius I don't know much about instance placeholders, but it looks like it's a different issue. What this PR fixes is NodePath that are used to point to a node in the scene, when the node is moved or renamed, while the problem in #44720 seems to be related to pointing to another scene as a file path when this path changes. Fixing #44720 would require specific editor code to update instance placeholders when files are moved in the file system.

@koodikulma-fi
Copy link

koodikulma-fi commented Mar 11, 2022

This feature is great, but there is one problematic use case, which could however be solved with something like: PROPERTY_USAGE_NO_NODE_PATH_CORRECTION

Background

In my case the problem occurs due to a custom "compiling" system, where the source scene contains extra nodes and setup, which is then "compiled" into a game-ready scene including various optimizations. One of the optimizations is storing all node paths within the compiled scene as node paths from the root node of baking, so there's no need to get them many times and again when reused. (On the uncompiled source side, things function like Godot expects: each path starts from the node it's stored in.)

Problem

Due to the new auto correction feature (which I really like otherwise), I'm getting errors / warnings in the editor whenever the tree is changed (about paths not being found) - and even worse, Godot might in certain cases do the auto-correction which messes up the functioning of the compiled scene.

Solutions

  • However, if there was a corresponding flag in the usage of property info dictionaries (using _get_property_list()), it would be trivial to fix the problem in the script side.
  • There is a work-around by not using NodePaths, but instead using Strings. However, this could cause problems in cases where TYPE_STRING vs. TYPE_NODE_PATH is used to detect other stuff. (--> This was problem in my case, but ended up solving it by prefixing the other path like strings with ":" since a valid node path will never start so.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants