Hello:

Can I get the 8 neighbors of a node independently whether they are connected or not?

Thank you

Hello:

Can I get the 8 neighbors of a node independently whether they are connected or not?

Thank you

Yes. Prepare for a bit messy code:

`

GridNode node = //Some node here

GridGraph graph = GridNode.gridGraphs[node.GetGridIndex()];

int index = node.GetIndex();

int x = index % graph.width;

int z = index/graph.width;

//Loop through neighbours

for (int i=0;i<8;i++) {

//Find the coordinates for the neighbour

int nx = x+graph.neighbourXOffsets[i];

int nz = z+graph.neighbourZOffsets[i];

```
//Make sure it is not out of bounds
if (nx < 0 || nz < 0 || nx >= graph.width || nz >= graph.depth) {
continue;
}
GridNode other = (GridNode)graph.nodes[index+graph.neighbourOffsets[i]];
```

}`

Thatâ€™s basically what the grid node does internally when getting neighbours. I have no build in function for it, so you will have to do with this code.

You might also want to use the grid graph directly to get node info.