Enter/exit triggers for grid nodes

I’m using a hexagonal grid graph and trying to create a system where you can identify what nodes are occupied as objects move around the graph. Essentially, I need to know when an object is occupying a node, when it leaves that node, and when it enters a new node.

For the first part, I’d imagine you would use GraphNode node = AstarPath.active.GetNearest(myObject.transform.position).node; to get the node your object is on but calling that every frame can’t be performant especially across multiple objects. So I need some way to determine leaving/entering a node so I can update the node highlight object’s position to be the center of the new node.

Feels similar to DynamicGridObstacle but I’m looking for more control over being notified about entering/exiting a node (I think? Maybe I’m wrong.)

Examples of what I’m trying to accomplish
Lots of grid based games do this kind of thing: finding a spot to place a building in an RTS by hovering over the map while the tiles are highlighted below as being available or unavailable. I’d imagine you’re calculating the nodes that are being touched and snapping some semi-transparent overlay on them as the cursor moves around.

Or like highlighting the occupied node beneath a selected object. Then, as the object paths along nodes it would highlight the new node when they enter it and un-highlight the old node when leaving it. I’d imagine that is detecting entry to a new node and snapping some semi-transparent image on them. Or doing the same kind of thing if a node is blocked—highlighting the node below the object with red.

Bonus points if someone can help me figure out how to snap objects to the A* hex grid in the editor :sweat_smile:

Hi

Occupancy is not something that is tracked by this package. You can, however, get the closest node to the agent’s current position using AstarPath.active.GetNearest(transform.position).node. See also https://arongranberg.com/astar/docs/usingnodes.html