diff --git a/assets/script/game/map/MissionComp.ts b/assets/script/game/map/MissionComp.ts index dd632cb3..855cc23a 100644 --- a/assets/script/game/map/MissionComp.ts +++ b/assets/script/game/map/MissionComp.ts @@ -170,15 +170,18 @@ export class MissionComp extends CCComp { // ======================== ECS 查询匹配器(预缓存) ======================== /** 匹配拥有 HeroViewComp 的实体(英雄/怪物视图) */ - private readonly heroViewMatcher = ecs.allOf(HeroViewComp); + private heroViewMatcher: any = null; /** 匹配拥有 SkillView 的实体(技能视图) */ - private readonly skillViewMatcher = ecs.allOf(SkillView); + private skillViewMatcher: any = null; /** 匹配拥有 HeroAttrsComp 的实体(英雄/怪物属性) */ - private readonly heroAttrsMatcher = ecs.allOf(HeroAttrsComp); + private heroAttrsMatcher: any = null; // ======================== 生命周期 ======================== onLoad(){ + this.heroViewMatcher = ecs.allOf(HeroViewComp); + this.skillViewMatcher = ecs.allOf(SkillView); + this.heroAttrsMatcher = ecs.allOf(HeroAttrsComp); this.showMemoryPanel = false // 注册生命周期事件 this.on(GameEvent.MissionEnd,this.mission_end,this) @@ -904,6 +907,7 @@ export class MissionComp extends CCComp { /** 清理所有英雄和技能 ECS 实体 */ private cleanComponents() { + if (!this.heroViewMatcher || !this.skillViewMatcher) return; const heroEntities: ecs.Entity[] = []; ecs.query(this.heroViewMatcher).forEach(entity => { heroEntities.push(entity); @@ -1059,6 +1063,9 @@ export class MissionComp extends CCComp { /** ECS 组件移除时销毁节点 */ reset() { this.PhaseTime = null as any; + this.heroViewMatcher = null; + this.skillViewMatcher = null; + this.heroAttrsMatcher = null; if (this.node && this.node.isValid) { this.node.destroy(); }