fix(skill): 修复技能碰撞检测中的空实体引用问题

在 SkillView 的 onBeginContact 方法中调整了防御性检查的顺序,确保在访问 targetView.ent 前先验证其存在性,避免潜在的运行时错误。同时将技能 6001 的 EType 从 collision 改为 distanceEnd 以修正其结束判定逻辑。
This commit is contained in:
panw
2026-03-19 09:45:46 +08:00
parent 8302515cf1
commit 33d88b2884
2 changed files with 9 additions and 8 deletions

View File

@@ -193,7 +193,7 @@ export const SkillSet: Record<number, SkillConfig> = {
6001: {
uuid:6001,name:"空挥",sp_name:"atk_s1",icon:"1026",TGroup:TGroup.Enemy,TType:TType.Frontline,readyAnm:"",endAnm:"",act:"atk",DTType:DTType.single,
ap:100,hit_count:1,hitcd:0.2,speed:720,with:0,
ready:0,EAnm:0,DAnm:9001,RType:RType.linear,EType:EType.collision,
ready:0,EAnm:0,DAnm:9001,RType:RType.linear,EType:EType.distanceEnd,
buffs:[],debuffs:[],info:"对前方目标造成100%攻击的伤害",
},
6002: {

View File

@@ -66,6 +66,13 @@ export class SkillView extends CCComp {
if (this.isDisposing) return;
if (!this.node || !this.node.activeInHierarchy) return;
const targetView = oCol.getComponent(HeroViewComp);
// 不是 HeroViewComp直接忽略
if (!targetView) return;
// 🔥 方案A防御性检查 - 在获取model前强制检查ent是否存在
if (!targetView.ent) {
mLogger.warn(this.debugMode, 'SkillView', '[SkillView] onBeginContact targetView.ent为空实体已销毁忽略此次碰撞');
return;
}
if (this.debugMode) {
const casterEid = this.sData.casterEid;
const targetName = targetView?.ent?.get(HeroAttrsComp)?.hero_name ?? '非英雄对象';
@@ -83,13 +90,7 @@ export class SkillView extends CCComp {
this.handle_collision_limit();
}
// 命中次数按碰撞事件统计:不依赖是否最终造成伤害
// 不是 HeroViewComp直接忽略
if (!targetView) return;
// 🔥 方案A防御性检查 - 在获取model前强制检查ent是否存在
if (!targetView.ent) {
mLogger.warn(this.debugMode, 'SkillView', '[SkillView] onBeginContact targetView.ent为空实体已销毁忽略此次碰撞');
return;
}
let model = targetView.ent.get(HeroAttrsComp);
if (this.debugMode) {
mLogger.log(this.debugMode, 'SkillView', `[skillView] 碰撞3`, oCol.group, seCol.group, model);