fix(scene): route root path to editor root in create flow. - #878
Merged
Conversation
_getOrCreateNodeByPath and _getCreatePathPreflight let NodeMgr.getNodeByPath('/')
short-circuit to cc.director.getScene(). In prefab mode that returns the
virtual scene hosting the prefab, not the prefab root, so a new node with
`path: '/'` landed as a sibling of the prefab root and got pruned by the
single-root constraint.
Detect root paths early with isRootNodePath so both helpers fall through to
`parent = currentScene` (= Service.Editor.getRootNode()), matching the
resolveNodeByPath helper already used by component.ts.
Contributor
Author
YuchenWell
approved these changes
Aug 21, 2026
bofeng-song
approved these changes
Aug 21, 2026
star-e
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
In prefab edit mode, right-clicking with no selection (Pink sends
path: '/'as parent) used to create the new node as a sibling of the prefab root, which the single-root constraint then discarded — the node "disappeared right after creation".NodeMgr.getNodeByPath('/')returnscc.director.getScene(), which in prefab mode is the virtual scene hosting the prefab, not the prefab root._getOrCreateNodeByPathand_getCreatePathPreflightaccepted that as a truthy parent, bypassing the caller'sparent = currentScenefallback (=Service.Editor.getRootNode()= the prefab root).The
component.tsadd-component path already handles this with aresolveNodeByPathhelper (#872). This aligns the node-create flow with the same convention.Changes
_getOrCreateNodeByPath(node.ts): widen the early-return guard from!pathto!path || isRootNodePath(path), so root-like inputs (/,//,///) fall through toparent = currentScene._getCreatePathPreflight(node.ts): same guard on theNodeMgr.getNodeByPathshort-circuit; the existing empty-pathPartsfallback already producesparent: currentScene, now unmasked for/.Tests
New file
src/core/scene/test/service-core/node-create-root-path-prefab.test.ts(4 cases):path: '/'in prefab mode: new empty node'ssetParentis called with the prefab root, not the virtual scene.path: '//'normalizes to the same behaviour.preflightCreate({ path: '/' })in prefab mode plansuiTransformPath: '/PrefabRoot'when the prefab root has aUITransform— i.e. preflight sees the prefab root as parent, not the virtual scene./ExistingChild) still resolve viaNodeMgr.getNodeByPathunchanged.Verified the tests catch the regression: reverting either
isRootNodePathguard innode.tsmakes cases 1 and 2 fail withcapturedResultNode.parentequal to the virtual scene instead of the prefab root.npx tsc --noEmitclean.jest src/core/scene/test/service-core/node-create-*— 18/18 pass (14 existing + 4 new).QA notes
Reproduce on any prefab:
Before this PR: the newly created node flashes and is gone. After: it appears as a direct child of the prefab root.