From 6b1ffeb770c982377182c651a62b599d9c4d270b Mon Sep 17 00:00:00 2001 From: Tore Bergebakken Date: Fri, 12 Jul 2024 13:41:24 +0200 Subject: [PATCH] Fix annoying navmesh agent exceptions --- Assets/Scripts/Gamestate/AIManager.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Gamestate/AIManager.cs b/Assets/Scripts/Gamestate/AIManager.cs index 9dbaaf929..aa958bc50 100644 --- a/Assets/Scripts/Gamestate/AIManager.cs +++ b/Assets/Scripts/Gamestate/AIManager.cs @@ -249,7 +249,8 @@ private void FindPlayers() agent.stoppingDistance = ShootingTarget ? shootingStoppingDistance : itemStoppingDistance; try { - agent.SetDestination(DestinationTarget.position); + if (agent.enabled) + agent.SetDestination(DestinationTarget.position); } catch { @@ -287,7 +288,9 @@ IEnumerator AnimateJumpCurve(float duration) normalizedTime += Time.deltaTime / duration; yield return null; } - agent.CompleteOffMeshLink(); + // TODO why is the agent sometimes not enabled here? + if (agent.enabled) + agent.CompleteOffMeshLink(); onLinkEnd?.Invoke(); }