From ed728bd1b90ba40369205564394d3e5133f5bb40 Mon Sep 17 00:00:00 2001 From: walkpan Date: Fri, 2 Jan 2026 15:08:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=A2=B0=E6=92=9E=E5=A4=84=E7=90=86):=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=98=B2=E5=BE=A1=E6=80=A7=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E8=8B=B1=E9=9B=84=E6=AD=BB=E4=BA=A1?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E7=A2=B0=E6=92=9E=E4=BD=93=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在SkillView中添加对目标实体是否存在的检查,避免访问已销毁实体 在HeroViewComp中死亡时禁用碰撞体,防止"尸体"参与后续碰撞 --- assets/script/game/hero/HeroViewComp.ts | 7 +++++++ assets/script/game/skill/SkillView.ts | 5 +++++ 2 files changed, 12 insertions(+) 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;