@
fix(ai): EnemyAiBrain 在 Start 构造 runtime,修入口态 locomotion NRE 入口状态 OnEnter 会声明 locomotion 意图(x.Locomotion.SetMode),但原在 Awake 构造 AiRuntime 时 EnterInitial 立即触发该 OnEnter——此时 EnemyBase.Awake 可能 尚未发现 _locomotion(两组件 Awake 顺序未定),导致 x.Locomotion 为 null 抛 NRE, brain 未建成 runtime。改在 Start 构造(所有 Awake 先于任一 Start),保证依赖就绪。 根因修复,非 null 兜底。P3 PlayMode 验证发现。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> @
This commit is contained in:
@@ -31,8 +31,13 @@ namespace BaseGames.Enemies
|
|||||||
// 根因暴露:漏配 id 直接报错,不静默兜底。
|
// 根因暴露:漏配 id 直接报错,不静默兜底。
|
||||||
Debug.LogError($"EnemyAiBrain 未配置 _definitionId:{name}", this);
|
Debug.LogError($"EnemyAiBrain 未配置 _definitionId:{name}", this);
|
||||||
enabled = false;
|
enabled = false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在 Start 构造 runtime:确保 EnemyBase.Awake 已发现 Locomotion/子系统后,
|
||||||
|
// 再触发入口状态 OnEnter(其会声明 locomotion 意图)。所有 Awake 先于任一 Start 执行。
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
var graph = AiDefinitionRegistry.GetGraph(_definitionId); // 不存在则抛异常
|
var graph = AiDefinitionRegistry.GetGraph(_definitionId); // 不存在则抛异常
|
||||||
_context = new EnemyBrainContext(_enemy);
|
_context = new EnemyBrainContext(_enemy);
|
||||||
_runtime = new AiRuntime(graph, _context);
|
_runtime = new AiRuntime(graph, _context);
|
||||||
|
|||||||
Reference in New Issue
Block a user