Agent doesn't repath when obstacle is placed ahead

Hi, first of all thanks for the great product!

I am building a tycoon game where AI agents move around performing various tasks, and the player can do things like build structures. When a new structure is placed I rescan that part of the graph with the bounds of the new structure’s collider to make those nodes Unwalkable.

The issue is that if the player places an obstacle ahead of an agent that is already in motion, the agent will keep walking through that obstacle even though the node is now unwalkable. The agent has a Seeker and AIPath component attached, and the Repath rate is 0.5. Once the agent has arrived at their destination and calculates a completely new path, it correctly navigates around the obstacle.

I have also tried manually calling SearchPath when the graphs are updated without success, so I’m not sure what I am doing wrong.

The following are the Awake, Movement and callback functions for my agent.

void Awake()
        seeker = GetComponent<Seeker>();
        aiPath = GetComponent<AIPath>();

        AstarPath.OnGraphsUpdated += GraphsUpdated;

public void MoveTo(Tile t, Action onArrival = null)
        targetTile = t;
        OnArrivedAtDestination = onArrival;
        seeker.StartPath(transform.position, (Vector3)targetTile.graphNode.position);

private void GraphsUpdated(AstarPath script)

As soon as I place the new object in the world I call this to update the graph:<BoxCollider2D>().bounds);

Finally, here is the issue in motion:


Instead of calling seeker.StartPath, you should adjust the destination property on the AIPath script. That will allow it to automatically recalculate its path.

ai.destination = (Vector3)targetTile.graphNode.position;

Thank you, that works perfectly!

1 Like