fix(hero): 修复实体销毁时可能出现的空引用问题

优化MissionComp中实体销毁逻辑,改为直接销毁实体让ECS处理组件清理
在HeroViewComp中添加多处model空值检查,防止销毁过程中访问null引用
移除reset方法中不必要的状态重置,由ECS系统统一处理
This commit is contained in:
2025-10-30 15:51:41 +08:00
parent e9cc5aae08
commit 56f45a7bb4
2 changed files with 26 additions and 9 deletions

View File

@@ -136,9 +136,17 @@ export class MissionComp extends CCComp {
}
private cleanComponents() {
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {entity.remove(HeroViewComp);entity.destroy()});
ecs.query(ecs.allOf(AtkConCom)).forEach(entity => {entity.remove(AtkConCom);entity.destroy()});
ecs.query(ecs.allOf(SkillViewCom)).forEach(entity => {entity.remove(SkillViewCom);entity.destroy()});
// 优化销毁顺序直接销毁实体让ECS系统自动处理组件清理
// 这样可以避免在组件reset方法中访问已经被销毁的实体引用
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {
entity.destroy();
});
ecs.query(ecs.allOf(AtkConCom)).forEach(entity => {
entity.destroy();
});
ecs.query(ecs.allOf(SkillViewCom)).forEach(entity => {
entity.destroy();
});
}