Support Forum

Thin walls in Hex Grid. How to disconnect nodes from one another?

    void SetConnection(Vector3 position1, Vector3 position2)
    {

        AstarPath.active.AddWorkItem(new AstarWorkItem(ctx =>
        {
            // Connect two nodes
            var node1 = AstarPath.active.GetNearest(position1, NNConstraint.None).node;
            var node2 = AstarPath.active.GetNearest(position2, NNConstraint.None).node;
            var cost = (uint) (node2.position - node1.position).costMagnitude;



            node1.AddConnection(node2, cost);
            node2.AddConnection(node1, cost);

            node1.ContainsConnection(node2); // True

            node1.RemoveConnection(node2);
            node2.RemoveConnection(node1);
        }));
    }

I tried to use this technique to create narrow walls in my hex grid, but they still show a connections. Also, can I make one way connections?

Hi

In the currently released version, the RemoveConnection function only allows you to remove custom connections. Not the default grid connections which are stored separately. You can either use node.SetConnectionInternal to disconnect them, or you can upgrade to the beta version which does allow you to remove grid connections as well.

You can. Though, some parts of the package may get confused if you have regions that are only accessible via a one-way link. Specifically, the “is there a valid path between these two nodes” code assumes that if there is a path from node A to node B, there is also a (potentially different, but still valid) path from B to A.

1 Like

Thank you, that’s great to know! I’ll check that out.