- 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.
Yeah it sounds like if you have a lot of units it can be useful to have something like this. It seems a little specialized but I’ll mark it as a request anyways. Per my own individual opinion, this would be something I’d moreso expect users to be implement themselves if they needed. Maybe I’m wrong and literally everyone would get value out of it! Regardless, I’ll move it to the right category- thanks for the feedback!
1 Like
Yeah it is kind of specific for games with a lot of active units. Also i use it as fast check if area is reachable, if units can walk over just one graph as much faster solution, then computing whole path is to check if target and start are in the same area. On the other hand, any request of path requires this as well (requesting start and target nodes). So let say in bad conditions we talk about 0.1ms per path request (normally it would be something like 0.02ms), even moving like squadron of 20 units make it sub-milisecond which is not noticable by an eye. On the other hand it can be seen as small fps drop in profiler. I had my own bug, that I computed the path 25x for each one because of it… and noticed it as 150ms lags in older version so it was very noticable 
Actually, you saying that kinda jostled my brain a bit-- I think the functionality you’re looking for does exist in a less manual form by way of a NearestNodeConstraint. There are two questions I’d have though, 1) does it not iterate through the entire graph if you use this and 2) if it does is it faster? I’ll have to check up on this at some point
Related, GetNearest that takes a NearestNodeConstraint:
That is what I am using and getting such results on 1km square map, with 51k tiles.
The function is something inbetween it is recursive function with some magic searching for closest node. If it was presaved in grid you just get all Nodes instantly in that tile and check just them. So almost instant results without recursion. (Hope I can share your function screenshot below)
Wait, 51,000 tiles with a 1000x1000m sized recast graph? That’s extremely dense- what’s your voxel size and tile size?
I run today different map which is smaller, but there are the stats:
If I had bigger of voxel size, tighter passages for soldiers in barracks were sometimes inaccessible.
If you absolutely need an extremely dense map for your game then I’d recommend using ProceduralGraphMover. Instead of one 500m graphs you can have a handful of, say, 25m graphs that move alongside your player and units. I use this to assign a group of NPCs the same map since they are part of the same spawn.