"SetDestination" error after disabling Nav Mesh Agent

Hey hey!

I followed Rick’s instructions in this section but found myself with an error.

“SetDestination” can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)
EnemyAI:ChaseTarget() (at Assets/Scripts/EnemyAI.cs:71)
EnemyAI:EngageTarget() (at Assets/Scripts/EnemyAI.cs:58)
EnemyAI:Update() (at Assets/Scripts/EnemyAI.cs:36)

It appears disabling the NavMeshAgent caused the error. I didn’t see anyone else ask this question, so I assume I’ve incorrectly applied something within my code or prefabs.

Thanks in advance for the help!

1 Like

Hi,

Maybe you could wrap the concerning line in an if-statement:
if (navmeshAgent.isActiveAndEnabled) { }.

Then test your game to see if you are getting any problems in your game or if the only problem was the error message in your console.

Did this help you fix it?


See also:

4 Likes

Nina, you have boss-level C# skills. Thank you, the error is gone.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms