Huge delay in starting the path when searching with endingcondition

Hey,

I’m trying to make my characters find the path around their target(if they have one). So I created the class “MyEndingCondition” as in example:

    public class MyEndingCondition : ABPathEndingCondition
    {
        // Maximum world distance to the target node before terminating the path
        public float maxDistance = 10;
        // Reuse the constructor in the superclass
        public MyEndingCondition(ABPath p) : base (p) { }
        public override bool TargetFound(PathNode node)
        {
            return ((Vector3)node.node.position - abPath.originalEndPoint).sqrMagnitude <= maxDistance * maxDistance;
        }

    }

And I’ve tried to use it in overrided SearchPath function:

        public override void SearchPath()
        {
            if (float.IsPositiveInfinity(destination.x) || pObj.isDead()) return;
            if (onSearchPath != null) onSearchPath();

            lastRepath = Time.time;
            waitingForPathCalculation = true;
            seeker.CancelCurrentPathRequest();

            shouldSearch = true;
            if (pObj.target != null)
            {

                if ((transform.position - pObj.target.transform.position).magnitude < pObj.person.activeInteraction.activationDistance)
                {
                    isStopped = true;
                    shouldSearch = false;
                }
                else
                {
                    float maxDistance = pObj.person.activeInteraction.activationDistance * 0.7f;
                    seeker.startEndModifier.exactEndPoint = StartEndModifier.Exactness.Original;
                    customPath = ABPath.Construct(tr.position + tr.up * (rvo.center - rvo.height * 0.5f), destination);
                    MyEndingCondition end = new MyEndingCondition(customPath);
                    end.maxDistance = maxDistance;
                }
                
            }
            else
            {
                seeker.startEndModifier.exactEndPoint = StartEndModifier.Exactness.Original;
                customPath = ABPath.Construct(tr.position + tr.up * (rvo.center - rvo.height * 0.5f), destination);
                if (destination == transform.position)
                    shouldSearch = false;
            }
            if (seeker is CultSeeker)
                (seeker as CultSeeker).ThatWasAnOrder = order;

            if (shouldSearch)
            {
                seeker.StartPath(customPath);

				if (order)
                {
					AstarPath.BlockUntilCalculated(customPath);
                    if (clickParticle != null) Destroy(clickParticle);
					if (customPath.vectorPath.Count > 0)
                    {
                        Vector3 InstantiationPosition = customPath.vectorPath[customPath.vectorPath.Count - 1];

                        if((InstantiationPosition - destination).magnitude< 0.1f)
                            Debug.LogError("ICG.Testing - Something's wrong");

                        clickParticle = Instantiate(CGC.i.PrefabsManager.Particles.ClickedOnMap, InstantiationPosition + Vector3.up * 0.5f, Quaternion.identity);
						correctPath = customPath.vectorPath;
                    }
                    else
                    {
                        clickParticle = Instantiate(CGC.i.PrefabsManager.Particles.ClickedOnMap, destination + Vector3.up * 0.5f, Quaternion.identity);
                    }

					movementPathController.DrawMovementPath (correctPath);

                    order = false;

                }

            }

        }

GIF:

It works, but somehow it takes a lot of time to start moving when the agent has the target. Did anyone else had this issue?

Ok. I’ve fixed it somehow.

Is there a way to use EndingDistanceProximity with seeker.startEndModifier.exactEndPoint = StartEndModifier.Exactness.Original??
Because if you use exactness.orginal the agent just goes to destination.

Not really. The exactEndPoint = Original option sets the last point of the path to be the exact target point that was specified in the ABPath.Construct call. So regardless where the ending condition says it will always end at the same point.
I recommend that you use either SnapToNode or ClosestOnNode.

Greetings,

What did you do to fix the delay when moving?
I’m using pathfinding for a TD game and agents seem to idle at spawn, more and more with each wave. First wave is fine, but the delay adds up.