A* Pathfinding Project

How to add point nodes in runtime?


#1

hello!

How to add point nodes in runtime?


#2

Hi

See https://arongranberg.com/astar/docs/pointgraph.html#AddNode


#3

HI!
I tried
AstarPath.active.AddWorkItem(new AstarWorkItem(ctx => {
var graph = AstarPath.active.data.pointGraph;
// Add 2 nodes and connect them
var node1 = graph.AddNode((Int3)transform.position);
var node2 = graph.AddNode((Int3)(transform.position + Vector3.right));
var cost = (uint)(node2.position - node1.position).costMagnitude;
node1.AddConnection(node2, cost);
node2.AddConnection(node1, cost);
// Required because we have changed connectivity of the graph
ctx.QueueFloodFill();
}));

but no nodes added …

Can U help me?


#4

Hi

Are you getting any errors?


#5

no error,but no nodes added in the Hierarchy.
Can I add nodes in the root node[],and then use updateXXX?


#6

Hi

This will add nodes without a corresponding GameObject.
You can add child nodes to the root GameObject and then use

AstarPath.active.Scan()

to recalculate the graph and thus take the new nodes into account though.