Constant Path Callback

Hello,

I’m attempting to use the ConstantPath class to get all nodes within movement range of the player.

I’m using a seeker to to calculate the path in a LayeredGridGraph setup, however I’m receiving an error when the callback triggers.

The code I’m using is taken from the documentation.
Documentation (arongranberg.com)

Error Received:
Exception: This function only handles ABPaths, do not use special path types. AIPath.cs:289)

Code:

   _seeker.StartPath(ConstantPath.Construct(transform.position, 7), OnPathCalculated);

    private void OnPathCalculated(Path path)
    {
        Debug.Log("OnPathCalculated");
        Debug.Log(((ConstantPath)path).allNodes.Count);
    }

The method OnPathComplete, it is indeed trying to cast newPath as an ABPath (AIPath.cs:287).
How can I get a callback from a ConstantPath? Or is there an alternative way, maybe without using the seeker? I am unable to cast a ConstantPath to a ABPath.

Looking around the forum, using the callback appears to be the correct way to get the nodes once the path is calculated.

Any insight would be appreciated.
Thanks.

Hi

Probably because the AIPath listens to completed paths from the seeker.
I’d calculate the ConstantPath separately without using the Seeker to avoid sending the completed path to the ai script.
Use

var path = ConstantPath.Construct(transform.position, 7000, MyOnPathComplete);
AstarPath.StartPath(path);

instead.

You may also be interested in Documentation which can be easier to use in some scenarios.

Ah perfect, thankyou.