diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index ea78c57c..033682fd 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -375,6 +375,13 @@ export class HeroViewComp extends CCComp { this.debugWarn("[HeroViewComp] realDead called but model is null, skipping"); return; } + + // 🔥 方案B:治理性措施 - 在销毁实体前先禁用碰撞体,从源头减少"尸体"参与碰撞 + const collider = this.getComponent(Collider2D); + if (collider) { + collider.enabled = false; + } + if(this.model.fac === FacSet.HERO){ // 英雄死亡:延迟触发死亡事件 oops.message.dispatchEvent(GameEvent.HeroDead, { diff --git a/assets/script/game/skill/SkillView.ts b/assets/script/game/skill/SkillView.ts index 0dc7dfb8..da2095e5 100644 --- a/assets/script/game/skill/SkillView.ts +++ b/assets/script/game/skill/SkillView.ts @@ -62,6 +62,11 @@ export class SkillView extends CCComp { if (oCol.group === seCol.group) return; // 不是 HeroViewComp,直接忽略 if (!targetView) return; + // 🔥 方案A:防御性检查 - 在获取model前强制检查ent是否存在 + if (!targetView.ent) { + console.warn('[SkillView] onBeginContact targetView.ent为空,实体已销毁,忽略此次碰撞'); + return; + } let model = targetView.ent.get(HeroAttrsComp); // console.log(`[skillView] 碰撞3`, oCol.group, seCol.group, model); if (!model) return;