Function GridNodeBase.AddPartialConnection

AddPartialConnection (GraphNode node, uint cost, bool isOutgoing, bool isIncoming)

Add a connection from this node to the specified node.

Public
void AddPartialConnection (

GraphNode

node

uint

cost

bool

isOutgoing

bool

isIncoming

)

Add a connection from this node to the specified node.

If the connection already exists, the cost will simply be updated and no extra connection added.

AstarPath.active.AddWorkItem(new AstarWorkItem(ctx => {
// Connect two nodes
var node1 = AstarPath.active.GetNearest(transform.position, NNConstraint.None).node;
var node2 = AstarPath.active.GetNearest(transform.position + Vector3.right, NNConstraint.None).node;
var cost = (uint)(node2.position - node1.position).costMagnitude;
node1.AddPartialConnection(node2, cost, true, true);
node2.AddPartialConnection(node1, cost, true, true);

node1.ContainsOutgoingConnection(node2); // True

node1.RemovePartialConnection(node2);
node2.RemovePartialConnection(node1);
}));

Warning

In almost all cases, you should be using the Connect method instead. If you use this method, you must ensure that you preserve the required invariants of connections. Notably: If a connection exists from A to B, then there must also exist a connection from B to A. And their outgoing and incoming connection flags must be set symmetrically.

Some graphs have a special representation for some connections which is more efficient. For example grid graphs can represent connections to its 8 neighbours more efficiently. But to use that efficient representation you'll need to call GridNode.SetConnectionInternal instead of this method.