A* Pathfinding Project

Assigning custom data to a node


I have place-able structures in my game. When a structure is placed, I need to tell the nodes that the structure is over that they belong to this structure. Something like

GridNodeBase node = gg.GetNode(structure.X, structure.Y);
node.Structure = this;

I know I can’t do that but is there another way?

I have a method to get the closest structure from an X and Y coordinate. So what I am looking to do is get the closest node using GetNearest, and then read the structure information from that node.




Perhaps the easiest way is to simply use a Dictionary.

var node2structure = new Dictionary<GraphNode, Whatever>();
node2structure[node] = structure;

It’s not the most performant way, but for your intended purpose I think it will work very well.