Exporting graphs to a JSON

I would like to export my graphs into a json file, is this possible to calculate them printing all nodes with their respective node references into a file?
If is this possible, how should i proceed? Thank you

Hi

There is a built in method to export graphs in the package. See https://www.arongranberg.com/astar/docs/save-load-graphs.php however it doesn’t store the node data as json for efficiency reasons.

Here is a page which shows how you can access all the node data if you want to export it yourself: https://www.arongranberg.com/astar/documentation/dev_4_1_8_94c97625/accessingdata.html

Hello, thank you for your fast reply.
Doesn’t this store data inside a binary file?
I tried using GetNodes function, but i need to know their linked nodes

Yes, it is in a binary file. It is a zip file and all graph settings are stored in a json format, but the node data is stored in binary form.

You can get all node connections by using the GraphNode.GetConnections method. That will return all nodes which the node is connected to.

var node = ...;
node.GetConnections(neighbour => {
     // node is connected to neighbour
});

Thank you, looks great.
Do you think this can go? Will it return all the data i need?

    gg.GetNodes (node => {
        if(node.Walkable) {
            nodes.Add(node.NodeIndex);
            node.GetConnections(neighbour => {
                if(neighbour.Walkable) {
                    Debug.Log("Node: " + neighbour.NodeIndex + " Conn: " + node.NodeIndex + " Pos: " + neighbour.position");
                }
            });
        }

    return true;
    });

I don’t know exactly which data that you need, but that will give you every single node’s connections.