I am working on GridGarph. Connect or disconnect node by Script.
If I Remove the Off-mesh link and the connect gridnode at same position, the agent can’t find connect .
the agent us Aipath and repath auto every 0.5s.
there is code connect node and create Nodelink2;
void ConnectNode(GraphNode startNode, GraphNode endNode)
{
GraphNode.Connect(startNode, endNode, 1000, OffMeshLinks.Directionality.TwoWay);
}
void AddLink2(GraphNode start, GraphNode end)
{
var link2 = Instantiate(_tempLinkPrefab);
link2.transform.position = (Vector3)start.position;
link2.end.transform.position = (Vector3)end.position;
link2.Apply();
}
//remove
if (Mouse.current.rightButton.isPressed)
{
EndPos = Mouse3D.GetMouseWorldPosition();
var node = _graph.GetNearest(EndPos).node;
node.GetConnections(x => GraphNode.Disconnect(node, x));
var offMeshLinks = AstarPath.active.offMeshLinks;
var linkNode = offMeshLinks.GetNearest(EndPos,0.5f);
if (linkNode.link !=null)
{
Destroy(linkNode.gameObject);
}
return;
}