fix(碰撞处理): 增加防御性检查并优化英雄死亡时的碰撞体处理
在SkillView中添加对目标实体是否存在的检查,避免访问已销毁实体 在HeroViewComp中死亡时禁用碰撞体,防止"尸体"参与后续碰撞
This commit is contained in:
@@ -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, {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user