How can I get a temporary path and return its length from script?

I am working on a combat algorithm and need to be able to account for the cost of moving to a point for the agent and its enemies (i.e. path length from agent to point and from enemies to point). I cannot do this with the agent’s own Seeker because it handles the actual movement. What I need is to get a temporary path and its length to calculate a “what if” scenario.

In general, I use a static MovementUtilities class that I can use where necessary. But I understand that to be able to start a path, I need a Seeker so I guess the static class option goes away. I can add a Pathfinding Manager monobehavior to my scene with a seeker and have it calculate a path and return its length. But then, what if 3 agents at the same time requests a temporary path and its length?

In short, is there a way to get a temporary path from point A to B and return its length, which will work with multiple agents requesting multiple temporary paths?

I am not sure if this is relevant but my agents use AIPath for movement.


You can calculate paths without using the seeker. See the bottom of this page:

Thanks man, this really helped. But now I have an issue with the AstarPath.StartPath(path). I have a static method like below:

public async static Task<float> GetPathLength(Vector3 startingPos, Vector3 targetPos)
        ABPath path = ABPath.Construct(startingPos, targetPos, `OnPathComplete`);
        // There should be an await here
        return path.GetTotalLength();

Before I return the result of GetTotalLength(), I need to await OnPathComplete with async. But it does not allow me to pass a task. And when it is a void, it cannot be awaited.

What would you recommend here?