Support Forum

How to connect Adjecent Grid Graphs when procedurally generated

Hi all.

I’m currently making an RTS game and am loving the Astar package.

However as noted in this thread: Seek path over multiple gridgraph's

You said it was possible to connect nodes of two graphs which I am doing like so:

                for (int x = 0; x < Graph.width; x++)
                {
                    var node = Graph.GetNode(x, 0) as GridNode;

                    if (NorthChunk != null)
                    {

                        var adjGraph = NorthChunk.Graph;
                        var adjNode = adjGraph.GetNode(x, adjGraph.Depth - 1) as GridNode;

                        var cost = (adjNode.position - node.position).costMagnitude;
                        node.AddConnection(adjNode, (uint)cost);
                        adjNode.AddConnection(node, (uint)cost);
                    }
                }

Unfortunately it seems like the nodes are still not connected.

Do you have any advice for this?

Many thanks :slight_smile:

I should also note that I have tried overlapping the Graphs and both have the same result (Seekers unable to path into other chunks/graphs

Turn on Grid Graph Settings -> Show Node Connections to see them.
The surface visualization only takes into account the built-in grid connections.

Hey Aron,

The way the Seekers are acting implied that there simply is no connection.
With Show Connections selected the below is the result:

Hm, it does not look like any connections have been added. Are you sure your code runs after you have scanned all the graphs for the last time? (and that you do not do any graph updates that might recalculate those nodes)

Hey,
My code appears to run fine.
And all of the GraphUpdates occur here:
image
but as you can see, the connections are only added if the .active.Scan has completed

Update:

I have just now noticed that there are infact connections here. It was just very hard to pick them out.

However, they seem to be a total mess haha:

Is there an easier way to allow Seekers to path to other GridGraphs that I’m missing?

Ah, it looks like your indexing is off somehow. I can’t really say what is wrong though. It looks like one of your graphs is rotated 90 degrees or something.