Fix crash on recovered orphaned nodes. #83604
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are a lot of issues in regards to how Godot recovers nodes from situations where an instanced or inherited node has its overall composition changed, resulting in nodes which might no longer reference a valid parent. However, the most notable issue right now is that if this happens, the scene will become corrupted to the point that it will crash if you attempt to close any scene containining one or more of these orphaned nodes. This is due to the default recover mechanism first extracting the nodes's path, then prepending it to the nodes name between an @ symbol. However, @ is a reserved character, so it sets it with the nocheck name, which subsequently updates the name, but does NOT update its parent's cache, resulting in failure if the node is referenced by path, and subsequently leads to crashes. The scene is essentially corrupted now beyond repair without manual text editing.
While there's a lot more that can be done in regards to recovering scenes with orphaned nodes (I recommend the next step should be constructing dummy nodes to recreate the original path composition as close as possible rather than shoving them in the root), I've changed from the reserved @ symbol to the ~ symbol and used the set_name command which does checks. This should at least now give users an oppertunity to manually repair their scene if nodes become orphaned, but may also be considering an editor-only UID system for scenes, which should more or less completely eliminate scene breakage like this.
Closes #83595