4.3.83 - seeker.pathCallback deprecated - Callback needed for SearchPath()

Hello Aron,

since seeker.pathCallback is deprecated now, I am missing a callback for when I do set the ‘destination’, and then call SearchPath()…

Currently only the SetPath() method does have a callback…



Could you elaborate on why you need this callback?

Well, I need to know when the path calculation has been finished … maybe I am not getting it, and there is already some functionality for that :slight_smile:

I currently do override RichAI, and in OnEnable I attach to the seeker.pathCallback event, after which I fire “my own event” in the overriden RichAI…

That seems to not work anymore in 4.3.83

But why do you need to know this?

You can already check the pathPending property.

Ok, polling would solve the issue… makes it a bit more complicated… because I start in a “state” that searches the new path, and then runs at least until it has found a solution once…

That means I would have to implement an Update() method or something, to poll for if the SearchPath is finished.

Simply put, it makes it more complicated for me :rofl:

Then the question arises: why have a callback for SetPath, and not for SearchPath? :smiley:

Sorry, no offense :grinning:

Maybe something like this:

IEnumerator DoStuff() {
    ai.destination = ...;
    while(ai.pathPending) yield return true;


Generally, the intention is that when you pass a path to the SetPath method, you leave the path’s callback as null.

I just noticed this method in AIBase:

/// <summary>Called when a requested path has been calculated</summary>
protected abstract void OnPathComplete(Path newPath);

Stupid me :rofl:

That would exactly be the solution… I override that method in my RichAI-overridden class (called MovementAgent, for whatever reason? :smiley: )

protected override void OnPathComplete(Path p)

    if (p.IsDone())

Just tried to leave it as null, and it throws me some warnings, that I should add a correct callback :smiley:

I actually do call the SetPath() method only when trying to calculate a Flee path…

Btw, somewhat related, I sometimes do get this error message, multiple times in a row, from searching a flee path:

Failed to find next corners in the path
UnityEngine.Debug:LogError (object)
Pathfinding.RichFunnel:Update (UnityEngine.Vector3,System.Collections.Generic.List`1<UnityEngine.Vector3>,int,bool&,bool&) (at ./Library/PackageCache/com.arongranberg.astar@4.3.83/Core/AI/RichPath.cs:401)
Pathfinding.RichAI:UpdateTarget (Pathfinding.RichFunnel) (at ./Library/PackageCache/com.arongranberg.astar@4.3.83/Core/AI/RichAI.cs:385)

I am using the flee code from here in the forum:

// The path will be returned when the path is over a specified length (or more accurately when the traversal cost is greater than a specified value).
// A score of 1000 is approximately equal to the cost of moving one world unit.
var theGScoreToStopAt = (int)(distance * 1000f);

// Create a path object
var path = FleePath.Construct(transform.position, fleeFrom, theGScoreToStopAt);
// This is how strongly it will try to flee, if you set it to 0 it will behave like a RandomPath
path.aimStrength = aimStrength;
// Determines the variation in path length that is allowed
path.spread = (int)Mathf.Max(4000, distance);

// Start the path and return the result to MyCompleteFunction (which is a function you have to define, the name can of course be changed)
seeker.StartPath(path, OnPathComplete);

(Using Mathf.Max with 4000 was just guessing from my side, maybe it would make it less often “fail to find next corners in the path” :slight_smile: )

Often - but not always - the AI will stop moving for a moment when this happens, and after a while just continues to function.