Connecting pointgraph nodes at runtime?

My game is a tile-based game. The map tiles are generated from a single prefab at runtime based on the desired mapsize. Each time a tile is created I add a PointNode at its position but I am unsure how to generate connections. I have a FloodFill() that runs after the world is finished generating but it doesn’t seem to make any connections. Here is what the PointGraph looks like when the game is paused:

Here is the code from the start() function of each tile which creates the node:
PointGraph pg = AstarPath.active.astarData.pointGraph; AstarPath.active.AddWorkItem (new AstarPath.AstarWorkItem (delegate () { PointNode node = pg.AddNode((Int3)getCenter()); }, null));

And here is the line which runs after the world is generated:
AstarPath.active.AddWorkItem(new AstarPath.AstarWorkItem(delegate() { AstarPath.active.FloodFill(); }, null));

Here is what it looks like when I start AN AI on a path towards position (-20,0,20) (using the scripts from the Getting Started guide on your API wiki): https://gfycat.com/TidyIdleArrowcrab

As you can see they all just go in random directions, sometimes none at all.

Hi

Considering that your world looks very grid like, isn’t it better to use a grid graph for this?

It would make sense to use a grid graph however the game will support changing the height of tiles, slope, etc. including building underground. So my understanding is a grid graph won’t work for this.

Hi

It does not support multiple overlapping levels, and while the layout you are describing would not work with the default grid graph connections (as it is hard to distinguish between a slope and an edge), but you can set the connections of each node individually as you see fit.

Hmm ok, but how do I make these connections actually happen? No matter what graph I’m using my root issue is I can’t seem to make the AI navigate on a graph that was generated at runtime.

Hi

For grid nodes you can set the connections like

var graph = AstarPath.active.astarData.gridGraph;
var node = AstarPath.active.GetNearest(somePosition, NNConstraint.None).node as GridNode;
// or node = graph.nodes[x + z*graph.width]

// Set connection in direction 3 to enabled
node.SetConnectionInternal(3, true);

// ...

// Do a flood fill here after all connections have been updated

See http://arongranberg.com/astar/docs/class_pathfinding_1_1_grid_graph.php#a33b21d81193b401670f85882ee240733 for how the directions map to numbers.
Note that the grid graph assumes that connections are bidirectional, so if node A has a connection to node B, then node B should have a connection to node A, otherwise you might get weird results.

How do I change the size of a grid graph during runtime? I’ve tried editing the depth and width from code but it doesn’t update the amount of nodes in the node array of the Grid Graph. It’s still 100 even though the size is 16fx16f

Edit: answer:
gg.UpdateSizeFromWidthDepth();

As far as I can tell I’ve set up the gridgraph correctly and it’s still giving me the exact same behavior that the pointgraph did. The AI just make random movements towards a point that’s nowhere close to the target I set, and I don’t see any gizmo lines to indicate what path is being created.

Console says no path found but then prints a path was found. The in-game text says the paths even have a length. I don’t know which to believe.

Hi

Do you think you could post a picture of the graph? (with the connections visible).

The ‘No path found’ and ‘Yay, we got a path back’ messages are not coming from any of the core pathfinding code, that is code that you have written (maybe as part of the get started tutorial), so it is hard for me to debug that.