I’ve been working with the system for a bit now and what I wanted to do was find all nodes an agent could reach within X nodes of themselves. (~10 Nodes for my Purposes)
I want to do this to get all the places the agent could go next so I can pass this list through some scorer algorithms on a behaviour tree to select the best location to go. But this works fine.
The issue being trying to find all the nodes. I’ve done this by finding the nearest node to the agent’s current position and from there creating a ConstantPath to find all available nodes within ~10 nodes (Duplicating nodes does not matter).
GraphNode node = AstarPath.active.GetNearest(transform.position, NNConstraint.Default).node;
cPath = ConstantPath.Construct((Vector3)node.position, 10000, null);
seeker = GetComponent<Seeker>();
seeker.StartPath(cPath);
This part works fine and the Agent is being moved as expected with no issues. What is cause for concern is that it throws a system exception.
Exception: This function only handles ABPaths, do not use special path types -
Pathfinding.AIPath.OnPathComplete (Pathfinding.Path newPath) (at Assets/AstarPathfindingProject/Core/AI/AIPath.cs:282)
Pathfinding.Seeker.OnPathComplete (Pathfinding.Path p, System.Boolean runModifiers, System.Boolean sendCallbacks) (at Assets/AstarPathfindingProject/Core/AI/Seeker.cs:326)
Pathfinding.Seeker.OnPathComplete (Pathfinding.Path path) (at Assets/AstarPathfindingProject/Core/AI/Seeker.cs:293)
Pathfinding.Path.ReturnPath () (at Assets/AstarPathfindingProject/Core/Path.cs:775)
Pathfinding.Path.Pathfinding.IPathInternals.ReturnPath () (at Assets/AstarPathfindingProject/Core/Path.cs:833)
Pathfinding.PathReturnQueue.ReturnPaths (System.Boolean timeSlice) (at Assets/AstarPathfindingProject/Core/Misc/PathReturnQueue.cs:54)
AstarPath.Update () (at Assets/AstarPathfindingProject/Core/AstarPath.cs:871)
It does this on this line of OnPathComplete in AIPath.cs
protected override void OnPathComplete (Path newPath) {
ABPath p = newPath as ABPath;
if (p == null) throw new System.Exception("This function only handles ABPaths, do not use special path types - ");
...
}
It does this because I’m using a ConstantPath. I was wondering if anyone knew how to do what I’m attempting to do without it throwing exceptions into the console. The behaviour works and there are no errors in that regard but in general I feel it’s best to solve errors thrown to the console to prevent it crowding out important messages throughtout development.
So is there a way to silence the exception? Or a function to start the Path using the ConstantPath that won’t trigger the exception? Sorry I’ve been workinig at it for a while and I’m not having luck.