使用cc.removeSelf,不会触发onDestroy,感觉是漏处理,还是有啥特别原因?
removeSelf是对node操作吧,不是Component
哪个版本?有demo么?
2.2呀,测试很简单
cc.Class({
extends: cc.Component,
onDestroy() {
cc.log(‘run onDestroy’);
},
clickMe() {
this.node.runAction(
cc.sequence(
cc.delayTime(0.5),
cc.removeSelf()
),
);
},
});
如果cc.removeSelf改为 cc.callFunc(() => {
this.node.destroy();
})
就会跑onDestroy,所以说明了removeself的逻辑没有处理这个
参考官方文档,cc.removeSelf本质是通过removeFromParent实现的,而removeFromParent和destroy是有区别的
觉得不改也是为了适配以往到用法吧,新的用法应该都用destroy去清理的, 建议官方加一个 cc.destroySelf() 吧