Enable/Disable the NavmeshAgent programatically?

Is there a way to uncheck the Navmesh Agent check box programatically? Can it be done using a NavMeshAgent object?


Change to:


Not go access to Unity at the moment but if the script is attached to the character you want to disable a component on then in c#

gameObject.GetComponent<NaveMeshAgent>().enabled = false;


gameObject.GetComponent(NavMeshAgent).enabled = false;

if the script isn’t on the character the you need to reference the gameObject it’s on with Find or FindGameObjectWithTag.

The above should work just replace gameObject with whatever variable use store the result of the Find.

Like I said not got access to Unity so sorry for any typo’s!

agent.enabled = !agent.enabled

!agent.enabled its not disabling agent always, some other function can activate this again (possible agent.isStopped =false or warp)
i think better stop updating agent (agent.updatePos = fasle, rotation = false and axis)

Go to a flat part of the map. Doesn’t matter if you are on a slope as long as it’s flat. Then, press ~ to open the console. Then, type in the console nav_mark_walkable then nav_generate