Support Forum

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.