Hello,
I am trying to get a listing of all the connecting nodes to each node of every graph. The variable ‘connections’ is a type of Pathfinding.Node[]. I read the documentation on it only to find that ‘connections’ is supposed to store an array of all the connecting nodes (which I want), but whenever I use ‘connections’, it always equals null.
AstarPath.active.graphs[index1].nodes[index2]
returns a valid node if my 2 indexes are in range, but using
AstarPath.active.graphs[index1].nodes[index2].connections
always returns null, and using
AstarPath.active.graphs[index1].nodes[index2] .connections[index3]
then gives me an error even though AstarPath.active.graphs[index1].nodes[index2] has connecting nodes to it.
Is there any way to fix this problem so that the connections array will work?
Thank you,
Michael S. Lowe
Why doesn’t the connections property work? Anyone? No matter what, connections always equals null so I have no access to any of its indexes. connections is an array of Pathfinding.Node.
From the node class:
`/** List of all connections from this node. This node's neighbour nodes are stored in this array.
* \
ote Not all connections are stored in this array, some node types (such as Pathfinding.GridNode) use custom connection systems which they store somewhere else.
* \\see #connectionCosts */
public Node[] connections;`
So that might be what you are running into if you are using a GridGraph.
Looks like this is how you would get other nodes from a GridNode. (Code from GetConnections method in GridNode)
`
GridGraph graph = gridGraphs[indices >> 24];
int index = GetIndex ();
int[] neighbourOffsets = graph.neighbourOffsets;
Node[] nodes = graph.nodes;
for (int i=0;i<8;i++) {
if (((flags >> i) & 1) == 1) {
Node node = nodes[index+neighbourOffsets[i]];
callback (node);
}
}
`
Might just want to set up using GetConnections rather than iterating through them yourself (assuming you have no islands in your graph.)