How to get PathNode G score?

Hi Aron,

In the v4.0, we had access to G score from any PathNode ( mypathNode.G ). In v5.0 how to get it ?

Best

This data is no longer stored on the nodes. It is only stored temporarily while the node is in the binary heap. If you use a custom path type, you can override the OnVisitNode method to get this info.

It seems that some node are not visited when using ConstantPath on reactGraph. Here are the method used to store & use the G score per node.

List gScores = new List();

public uint GetPathNodeGScore(int i)
{
if (i < allNodes.Count)
{
uint nodeIndex = allNodes[i].NodeIndex;
if (nodeIndex < gScores.Count)
return gScores[(int)nodeIndex];
}
return uint.MaxValue;
}

public uint GetPathNodeGScore(GraphNode node)
{
uint nodeIndex = node.NodeIndex;

 if(nodeIndex < gScores.Count)
         return gScores[(int)nodeIndex];

 return uint.MaxValue;

}

protected override void Reset()
{
base.Reset();

 gScores.Clear();

}

public override void OnVisitNode(uint pathNode, uint hScore, uint gScore)
{
base.OnVisitNode(pathNode, hScore, gScore);

 // Temp code : just increase array on demand if out of bound
 while (pathNode >= gScores.Count)
 {
     gScores.Add(uint.MaxValue);
 }
 gScores[(int)pathNode] = gScore;

}

See attached screen when I displayed the G score all in red. As you can see, there are some green nodes surrounded by all red which seems to tell that those node was not visited. Is it possible ? Note that the big green square is something not walkable and exluded from search which is normal there. The issue is more related to the 2 green triangles close to it (I have many of these issues on the mesh).

Many thks for your help
Best

In v5 each triangle node actually has 3 path nodes. One for each side of the triangle. This is controlled by the GraphNode.PathNodeVariants property. So I would recommend that you instead keep a Dictionary<GraphNode, int>, and then populate it with the minimum g score that you see for that graph node.
You can convert a path node index to a graph node using pathHandler.GetNode(nodeIndex).

Many thks for your quick response. In the code below, it seems that I am not passing by the else case where a lower score is found :

Dictionary<GraphNode, int> gScores = new Dictionary<GraphNode, int>();

public override void OnVisitNode(uint pathNode, uint hScore, uint gScore)
{
base.OnVisitNode(pathNode, hScore, gScore);

GraphNode node = pathHandler.GetNode(pathNode);

int storeGScore = int.MaxValue;
if (gScores.TryGetValue(node, out storeGScore) == false)
    gScores.Add(node, (int)gScore);
else if (gScore < storeGScore)
    gScores[node] = (int)gScore;

}

Do I missed something ? Anyway, the result looks better. I will investigate more.

Best

Looks reasonable to me.