Direct access to graph data question

Hello. I have a question or maybe a bug report.

The documentation says that we can edit nodes directly “Using direct access to graph data” Graph Updates during Runtime - A* Pathfinding Project

var node = gg.GetNode(x, z);
node.Walkable = …

but if I edit the node.Tag for an area and then after some time update this area using GraphUpdateObject I get erased/wrong tags in graph where I used GraphUpdateObject. This happens because GridGraph.nodeData is not updated when changing node.Tag directly. Data from GridGraph.nodeData is used for GraphUpdateObject.

this looks like a bug and editing nodes directly leads to an error when further updating the graph. Or am I doing something wrong?

I do not use only GraphUpdateObject because I need to update tags often and UpdateGraphs+GraphUpdateObject does it slowly.

Hi

Two things to make sure:

  1. Are you recalculating the grid graph connections after setting the walkability? (e.g. by calling GridGraph.RecalculateAllConnections or GridGraph.RecalculateConnectionsInRegion). This will propagate some data to gridGraph.nodeData.
  2. If you are using erosion, make sure to set node.WalkableErosion as well. This is the walkability value before erosion is applied, and if erosion is used, the final walkability is calculated from this.

I don’t change the walkability, I only change the tags:

node.Tag =

and I think I don’t need to call RecalculateConnectionsInRegion because tags don’t change connections.

to fix this i use a hack:

node.Tag =
graph.nodeDataRef.tags[i] =

(I made nodeDataRef public)

I use AstarWorkItem for this to avoid multithreading issues when accessing graph.nodeDataRef

perhaps a method like RecalculateConnectionsInRegion would be useful, but without updating connections, to update gridGraph.nodeData.

but I also need the fastest way to update tags in the graph during runtime.

1 Like