Raycast graph GetNearest() low performance

  • A* version: [5.3.7]
  • Unity version: [2022.3.62f3]

I found out that if I want to frequenly check if path is reachable, or any wortk with pathing, I need to use AstarPath.active.GetNearest function. Then for example if units use only one graph, to walk on, I can simply check if target is reachable by comparing if end is in the same area as the start. It is quite fast, but this single function takes in my case 0.4 ms and I found out, that it will go through all nodes and check which one fits. When there are some voxels, I wonder, if there could be option to bake that nodes into voxels. So each voxel carries info of all nodes inside and when calling GetNearest I will just check nodes which are inside that voxel on the asked position. Even better for RTS games and some other games which works on XZ graph only it could be 2D grid (tiles in navmesh). This would make this what I think only slow function to significantly boost performance for a small cost of memory. Because of that I believe it should be an option. I just wonder, what is your opinion to this feature and if possible will by officially implemented or not?

P.S. Updated A* to [5.4.6]
and it seems faster (I see numbers from 0.005ms up to 0.074ms)
Still might be thought as improvement if you have for example thousand units and try to check multiple positions in one frame for them. But no longer such needed feature.

On the other hand I hit a wall, if I want to use custom constraint, which is not created from walkable first and then the modified, I need to expand your NearestNodeConstraint code by adding for example this:

public static NearestNodeConstraint NNland = new NearestNodeConstraint
{
traversal = TraversalConstraint.None,
area = -1,
maxDistanceSqr = -1,
graphMask = GraphMask.FromGraphIndex(0),
walkable = WalkabilityConstraint.Walkable,
distanceMetric = DistanceMetric.ClosestAsSeenFromAbove()
};

as Traversal is internal and does not work externally so anytime I will update it, will have to copy that code.