Total cost between two nodes?

Hello, in a turn-based game I’m using the following code to calculate the possible nodes reachable with the unit’s movement:

var path = ConstantPath.Construct(unit.transform.position, movementPoints);
path.traversalProvider = unit.traversalProvider;
AstarPath.StartPath(path);
path.BlockUntilCalculated();

foreach (var node in path.allNodes) {
      if (node != path.startNode) {
               //here I take each possible node and highlight it in the map
       }
}

It all works fine, and also I can make the unit move along the path to the selected node. But I have no idea how to find out the exact movement cost for each node (including *1.5 heuristic for diagonals). the thing is, I need this figure to show the movement point cost in the UI, and to deduct it from the unit movement for that turn, so the player can perform the movement in different small steps if he wants.

I am using the Pro version.

Any help would be welcome!

I came up with a solution that doesn’t seem to be optimal… going node by node and calculating an ABPath between the starting node and it. However this means I am calculating everything twice, is there a way to somehow get the path length to each node when it gets calculated the first time? Maybe I shouldn’t be using ConstantPath.Construct but something else?

Hi

Sorry for the late reply.
Currently for grid graphs there is actually no super easy solution.
The shortest one I can come up with right now is this:

var node1 = ... as GridNodeBase;
var node2 = ... as GridNodeBase;
var di = node2.NodeInGridIndex - node1.NodeInGridIndex;
var graph = node1.Graph as GridGraph;
var direction = graph.neighbourOffsets.IndexOf(di);
if (direction == -1) throw new System.Exception("Nodes are not adjacent");
uint cost = graph.neighbourCosts[direction];