A* Pathfinding Project

Noobie question about point graph


I am changing our current pathfinding to A* Pathfinding Project. I have some questions. Our project needs following:

  1. The game is in 2D. We have 2D polygon colliders for obstacles (buildings and stuff)
  2. Game already generates graph node points. Those are made by creating a node point for every point in a 2D polygon collider that is expanded outward from the collider by fixed amount. This works very well.
  3. I want to add those points to the pointgraph from the code. I would prefer to just give positions, instead of needing to have transform, root or tag.
  4. After that I would like from code again, that the connections are calculated. If there is collider between two points, there is no connection.
  5. So far I have figured out following:

a) Add Pathfinder component to a GameObject
b) Add points using following slightly modified code that I found:
AstarPath.active.AddWorkItem(new AstarWorkItem
(ctx =>
var graph = AstarPath.active.data.pointGraph;
foreach (Vector3 point in nodePositions)
c) I don’t know how now let the system calculate which nodes are connected to which?

Can anybody help me in the right direction?


Ah, it looks like the relevant method for that is private at the moment. You can make the PointGraph.ConnectNodes method public and then call it like:

 foreach (var progress in ConnectNodes()) {}