Calculatepartial has a very high cost

Hi, while calculating a route over a destination surrounded by a non-traversable label area, I assign the option calculate partial = true, this results in a desired route, but the problem is that to calculate this route requires a lot of time, how can I receive this route in a fast way?


This is a documented caveat of calculatePartial:

The bottom line is that it cannot know when to stop searching. It is possible, with some trickery, to limit the path so that it refuses to search for longer paths than a given threshold. But this would prevent it from finding the best path in some situations.

I am using endingcondition but my units stop working, here is my example:

XPath p = XPath.Construct(currentPosition, destination);
p.traversalProvider = CustomTraversalProvider;
p.calculatePartial = partial;
MyEndingCondition ec = new MyEndingCondition(p);
p.endingCondition = ec;
SetPath(p, false);

public class MyEndingCondition : ABPathEndingCondition

            // Maximum world distance to the target node before terminating the path
            public float maxDistance = 1000000;

            // 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;

You’ll need to explain more clearly than “stop working” to let me have any chance of helping.

sorry, my translation is sometimes bad.
When I assign the condition, the agents don’t walk, I forced the TargetFound function to always return true and the agents still don’t walk

I have also tried to use XPath without assigning the condition and so it works, but I need to add the condition…

What kind of path do you get back?

Note that if it always returns true, then the agent will think the node it starts on is a valid end node, and so it will calculate a path of length 0 and the agent will not move.

ok, dejé la función como antes:
public override bool TargetFound(PathNode node)
return ((Vector3)node.node.position - abPath.originalEndPoint).sqrMagnitude <= maxDistance * maxDistance;

this then returns p.path.count = 1 always

Did you try lowering this?

Yes, I’ve lowered it to 10,000 and 1000, but it’s still the same… p.path.count=1

That still allows any node within 30 meters to be accepted as a target. Try lowering it more.

It doesn’t work with 100, if I assign 10, some routes work and others don’t, the ones that usually don’t work are the short routes

Any routes that would be shorter than sqrt(10) units would always return a path with length 1, because in those cases, your TargetFound function will return that the start node of the path is a valid point to stop searching at.

I got that function from a forum post, I don’t know if it really works for my case, the case is to avoid very long routes to avoid calculatepartial=true, I would like to know what kind of condition I should add in TargetFound to avoid these long routes

I thought of a trick to get a valid destination when I know of these cases where the destination is surrounded by a non-traversable area, but to apply this trick, I need to know if the obtained route is invalid, but it takes a long time to receive such a route.

if (p.error)
MyFunctionTrack(); //This function is based on searching for the closest invalid node and then searching in the opposite direction between the destination and this invalid node for a valid node