prefab中放入一个editbox来观察这个bug
const node = instantiate(this.prefab);
this.scheduleOnce(() => {
node.parent = this.node;
})
会发现点击editbox后,输入框位置不对,根源是node中这个逻辑存在问题
/**
* @en Whether the node's transformation have changed during the current frame.
* @zh 这个节点的空间变换信息在当前帧内是否有变过?
*/
get hasChangedFlags (): number {
return this._flagChangeVersion === globalFlagChangeVersion ? this._hasChangedFlags : 0;
}
this._flagChangeVersion与globalFlagChangeVersion不想等,导致edit-box-impl中的更新逻辑没有执行。
public update (): void {
const node = this._delegate!.node;
if (!node.hasChangedFlags) {
return;
}
this._updateMatrix();
}
如果将scheduleOnce换成setTimeout,可以恢复正常
const node = instantiate(this.prefab);
setTimeout(() => {
node.parent = this.node;
})