Pass precalculated paths to pathfinder

I am writing a game with many entities in which I am trying to squeeze as much performance out of as possible. I have also noticed that sometimes the paths created are not straight lines, which for most scenarios is fine for me but not for cases when the AI is close to the player.

I am already doing linecasts for the AI to determine sight of the player. In this instance, I would like to pass the seeker/AstarPath/AIPath the line as the path without doing any other calculation. Is this possible?

I am considering extending the Seeker class with a SetPath method that just does CancelCurrentPathRequest and OnPathComplete.

Edit: This approached worked. If there is an obviously better method please let me know.

This approach will not work because it would be very awkward to deal with corners. I am instead going to create a StraightLinePath will will be requested in this condition, which will use spatial awareness additionally to optimize the process, and then optimistically create a path directly, only doing any modifications when unwalkable nodes are found.

That ended up being much more simple to implement by creating a custom heuristic that considers the distance from the passed line.

Hi

Seems you have managed to solve the issue now. I’d just like to highlight that the movement scripts (AIPath/RichAI/AILerp) have a SetPath method which I think should do roughly what you want.

I have this same issue, and I tried using SetPath. SetPath rejected my pre-calculated path because the pipeline state of the path was ReturnQueue instead of Returned.

I was following the instructions of the docs, and constructing the path as follows:

  • Call ABPath Construct
  • Pass the resulting path to AstarPath.StartPath
  • Wait for the callback to fire, then pass the path to AILerp.SetPath

Is there something I’m missing? I looked into the pathqueue classes, but it wasn’t obvious how to pull the specific path I’d like out of the queue, or whether that would even change its pipeline state properly.

I altered the code of SetPath to accept both Returned and ReturnQueue pipeline states as a workaround, but it feels hacky.

@Skeletoneyes That use case has been fixed in the beta version (see https://www.arongranberg.com/astar/download).

4.3.15 (2020-03-11)

  • Fixed ai.SetPath did not accept paths if you called it from the OnPathComplete callback for the path.