How to add point nodes in runtime?

hello!

How to add point nodes in runtime?

1 Like

Hi

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

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?

Hi

Are you getting any errors?

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

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.