Seeker searching multiple times when they should only once

Hello,
I am using the following code to have a seeker wander my recast graph randomly:

 if (!isSpotted && !isMoving)
        {
            if (parent.GetComponent<Seeker>().IsDone() == true)
            {
                parent.GetComponent<RichAI>().canSearch = false;
                parent.GetComponent<RichAI>().canMove = true;
                RandomPath rp = RandomPath.Construct(parent.transform.position, UnityEngine.Random.Range(5000, 20000));
                parent.GetComponent<Seeker>().StartPath(rp);
                isMoving = true;
            }
        }

I find that each time startpath is called, it is called 4 or 5 times, causing the entity to rotate rapidly between each path as the next subsequent path overrides the previous (all under 1 second). I am using the newest beta, RichAI, RVO and the destination setter, though at certain times I just want to submit straight to startpath (fleeing and random movement). Is startpath the best way to call the different path types with this setup? Any thoughts on why it would call multiple times rapidly?

Hi

That looks odd. When in your code are you setting isMoving to false?

I should have copied the entire script (I will when I get home). Anyway, I do a check in update that is essentially:

if(isMoving)
{
if(parent.GetComponent<Seeker>().velocity == Vector3.zero)
     {
     isMoving = false
     }
}

I ended up adding the isDone check and tried removing the isMoving variable altogether, though then it would rapidly spit through new paths without ever settling on one.

No other scripts should be attempting to call new paths, at least not any of mine.

NEVERMIND… I figured it out. Your hunch (based on so little information) was correct. I changed it so that OnTargetReached changes the isMoving field to false. Now it works perfectly. :slight_smile:

Yup.
Your isMoving boolean will always be set to true at the end of that Update as obviously the AI will not have started to move the same frame as you requested the path.