mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
avoid persist node's uuid collision (#8285)
This commit is contained in:
@@ -476,7 +476,7 @@ export class Director extends EventTarget {
|
||||
for (let i = 0; i < persistNodeList.length; i++) {
|
||||
const node = persistNodeList[i];
|
||||
node.emit(legacyCC.Node.SCENE_CHANGED_FOR_PERSISTS, scene.renderScene);
|
||||
const existNode = scene.getChildByUuid(node.uuid);
|
||||
const existNode = scene.uuid === node._originalSceneId && scene.getChildByUuid(node.uuid);
|
||||
if (existNode) {
|
||||
// scene also contains the persist node, select the old one
|
||||
const index = existNode.getSiblingIndex();
|
||||
|
||||
+4
-1
@@ -566,6 +566,8 @@ export class Game extends EventTarget {
|
||||
} else if (node.parent !== scene) {
|
||||
debug.warnID(3802);
|
||||
return;
|
||||
} else {
|
||||
node._originalSceneId = scene.uuid;
|
||||
}
|
||||
}
|
||||
this._persistRootNodes[id] = node;
|
||||
@@ -579,11 +581,12 @@ export class Game extends EventTarget {
|
||||
* @zh 取消常驻根节点。
|
||||
* @param node - The node to be removed from persistent node list
|
||||
*/
|
||||
public removePersistRootNode (node: { uuid: string; _persistNode: boolean; }) {
|
||||
public removePersistRootNode (node: Node) {
|
||||
const id = node.uuid || '';
|
||||
if (node === this._persistRootNodes[id]) {
|
||||
delete this._persistRootNodes[id];
|
||||
node._persistNode = false;
|
||||
node._originalSceneId = '';
|
||||
legacyCC.assetManager._releaseManager._removePersistNodeRef(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,6 +328,9 @@ export class BaseNode extends CCObject implements ISchedulable {
|
||||
|
||||
protected _siblingIndex = 0;
|
||||
|
||||
// record scene's id when set this node as persist node
|
||||
public _originalSceneId = '';
|
||||
|
||||
/**
|
||||
* Set `_scene` field of this node.
|
||||
* The derived `Scene` overrides this method to behavior differently.
|
||||
|
||||
Reference in New Issue
Block a user