Path calculating, but character not moving

I’m using two different built-in methods to generate paths:
RichAI.GetPath(Transform target), which works.
seeker.StartPath(Path randomPath), doesn’t work.

The first generates the path to the target, and the agent moves just fine.

The second one calculates the path, as indicated by the gizmos, but the agent never moves.

What am I missing?


The Seeker component only handles path calculations, it is not a movement script.
The RichAI script is a movement script and it will call the Seeker component to handle the pathfinding calculations.


OK. I understand that part.

Now, if I’m extending the RichAI script, can I pass that path into an existing method, do I need to write a custom method, or do I pass it into another script entirely?

I did get it to work a bit by creating a coroutine. However, only the first 2 agents find and navigate a path, and they don’t seem to go very far. The third will rarely succeed, and the rest get “Path Failed”. All of these are prefabs that generate at runtime.

IEnumerator WanderUpdate()
	randomPath = Pathfinding.RandomPath.Construct(transform.position, 50);
	yield return 0;
	StartHasRun = true;
	yield return 0;

I finally figured out what I was doing wrong. I needed to implement:
while(!seeker.IsDone()) yield return null;
inbetween the seeker.StartPath and RichAI.OnEnable()


If you are doing something like

richAI.enabled = true;

That will work sometimes, but it could fail randomly. The proper way to do it is to override the UpdatePath method in the RichAI script. Create a subclass and add this method.

public override void UpdatePath () {
        // First part is copied from the RichAI script
        canSearchPath = true;
        waitingForPathCalc = false;
        Path p = seeker.GetCurrentPath();
        //Cancel any eventual pending pathfinding request
        if (p != null && !seeker.IsDone()) {
            // Make sure it is recycled. We won't receive a callback for this one since we
            // replace the path directly after this
            p.Claim (this);
            p.Release (this);
        waitingForPathCalc = true;
        lastRepath = Time.time;

        // Add your own path searching logic here
        seeker.StartPath (tr.position, target.position);

Also. OnEnable is a method called by Unity, you should rarely have to call it yourself.
The only reason the RichAI script does call it directly is to avoid duplicating code.

I was having a problem getting the agent to move on the path at the start, and implementing the UpdatePath override did fix that. Thanks!

The reason I started using the OnEnable function is because I saw that you had it in GetPath, which I call to get a path to a specific target; and currently, I can’t get the agent to move along a random path without calling OnEnable. As a side note, I do toggle reapeatedlySearchPath before and after the call, otherwise it generates a new path every frame.

So far, I haven’t had any problems with failed paths