From 2bc107dcbcdac8e24bc34c0de13a28e3a4da7a33 Mon Sep 17 00:00:00 2001 From: bofeng-song Date: Fri, 17 Oct 2025 17:01:22 +0800 Subject: [PATCH] [feat] add _registerIfAttached for NODEJS platform (#25) --- cocos/scene-graph/node-dev.ts | 4 ++-- cocos/scene-graph/node.ts | 4 ++-- cocos/scene-graph/scene.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cocos/scene-graph/node-dev.ts b/cocos/scene-graph/node-dev.ts index 51a5e2dadb..ef7988509e 100644 --- a/cocos/scene-graph/node-dev.ts +++ b/cocos/scene-graph/node-dev.ts @@ -22,7 +22,7 @@ THE SOFTWARE. */ -import { EDITOR, DEV, TEST } from 'internal:constants'; +import { EDITOR, DEV, TEST, NODEJS } from 'internal:constants'; import { CCObjectFlags } from '../core/data/object'; import * as js from '../core/utils/js'; import { legacyCC } from '../core/global-exports'; @@ -45,7 +45,7 @@ export function nodePolyfill (Node): void { }; } - if (EDITOR || TEST) { + if (EDITOR || TEST || NODEJS) { Node.prototype._checkMultipleComp = function (ctor): boolean { const existing = this.getComponent(ctor._disallowMultiple); if (existing) { diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index fa2286ad6e..90c9ac3936 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -23,7 +23,7 @@ */ import { ccclass, editable, serializable, type } from 'cc.decorator'; -import { DEV, DEBUG, EDITOR, EDITOR_NOT_IN_PREVIEW, USE_UI_SKEW } from 'internal:constants'; +import { DEV, DEBUG, EDITOR, EDITOR_NOT_IN_PREVIEW, USE_UI_SKEW, NODEJS } from 'internal:constants'; import { Layers } from './layers'; import { NodeUIProperties } from './node-ui-properties'; import { cclegacy } from '../core/global-exports'; @@ -1497,7 +1497,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { // detach self and children from editor const parent = this._parent; const destroyByParent: boolean = (!!parent) && ((parent._objFlags & Destroying) !== 0); - if (!destroyByParent && EDITOR) { + if (!destroyByParent && (EDITOR || NODEJS)) { // TODO: `_registerIfAttached` is injected property // issue: https://github.com/cocos/cocos-engine/issues/14643 (this as any)._registerIfAttached!(false); diff --git a/cocos/scene-graph/scene.ts b/cocos/scene-graph/scene.ts index 498ccc6cb5..40701ad455 100644 --- a/cocos/scene-graph/scene.ts +++ b/cocos/scene-graph/scene.ts @@ -23,7 +23,7 @@ */ import { ccclass, serializable, editable } from 'cc.decorator'; -import { EDITOR, TEST } from 'internal:constants'; +import { EDITOR, NODEJS, TEST } from 'internal:constants'; import { CCObject } from '../core/data/object'; import { assert, getError } from '../core/platform/debug'; import { RenderScene } from '../render-scene/core/render-scene'; @@ -192,7 +192,7 @@ export class Scene extends Node { * @mangle */ public _activate (active = true): void { - if (EDITOR) { + if (EDITOR || NODEJS) { // register all nodes to editor // TODO: `_registerIfAttached` is injected property // issue: https://github.com/cocos/cocos-engine/issues/14643