When SiblingIndex is busy, setSiblingIndex of another node may be set to 0.
Cocos Creator v2.1.0.
ProcA.ts
const {ccclass, property} = cc._decorator;
@ccclass
export default class ProcA extends cc.Component {
private childNodes: cc.Node[] = [];
protected start(): void {
for (let i = 0; i < 50; ++i) {
const newNode = new cc.Node();
newNode.parent = this.node;
this.childNodes.push(newNode);
}
}
protected update(): void {
this.childNodes.forEach(e => e.setSiblingIndex(0));
}
}
ProcB.ts
const {ccclass, property} = cc._decorator;
@ccclass
export default class ProcB extends cc.Component {
private siblingNode: cc.Node;
private createSiblingNode(): cc.Node {
const node = new cc.Node();
node.parent = this.node.parent;
return node;
}
protected update(dt): void {
if (this.siblingNode) {
cc.log(this.siblingNode.getSiblingIndex());
this.siblingNode.destroy();
}
this.siblingNode = this.createSiblingNode();
// The SiblingIndex set here is occasionally 0.
this.siblingNode.setSiblingIndex(this.node.getSiblingIndex() + 1);
}
}