Totally cancel a navigation request

Hi,

I know this has been answered before, but wonder if there is a more up-to-date answer.

For my agent, I am using Unity’s Character Controller, along with Seeker and AIPath. And I am using a simple Grid Graph.

I start the navigation by simply setting agent.destination = destination. Whenever the agent gets within a certain distance from the destination, I would like to totally cancel this navigation, and stop the agent completely (as it has “run out of fuel”). I know there are various ways to do this, but what is the best/recommended way?

Thanks!

Hi

You can use

ai.SetPath(null);
ai.canSearch = false; // To prevent it from recalculating the path

If you want to stop the agent immediately without it smoothly slowing down then use

ai.SetPath(null);
ai.canSearch = false; // To prevent it from recalculating the path
ai.canMove = false;

Hey,

are you positive SetPath(null) actually clears the path?

I call this code, and my unit stops, but the path is still there (see image)

public void ClearPath()
    {
        aiPath.SetPath(null);
        aiPath.canSearch = false;
    }

It makes the AI component clear its path. The Seeker is the one drawing the green line, and it will always draw the last path request regardless of if the ai script has tha path or not.

i have the same problem with CodeCachet

i am using Recast graph and send the position via ai.destination = vector3
then call
ai.SetPath(null);
ai.canSearch = false; // To prevent it from recalculating the path
ai.canMove = false;

in the middle of its journey. It stops as expected but as soon as canSearch and canMove are true again, it still continues to the same position.
The only way i can get around this is to put -
ai.destination = transform.position;