Currenty I use this function to get the nearest walkable node near to my mouse cursor
public static GraphNode GetNearestWalkableNode(Vector3 position)
{
var constraint = NNConstraint.None;
constraint.constrainWalkability = true;
constraint.walkable = true;
return AstarPath.active.GetNearest(position, constraint).node;
}
This returns GraphNode. But I use a LayerGrid and there is also GridNode (for GridGraph) and LevelGridNode (for LayerGraph). How can I use them? It’s not possible to just cast them as LevelGridNode and I’ve found no method in the LayerGrid that returns me a LevelGridNode in any way.
When using a Layered grid graph, the node type will be LevelGridNode. When using a regular grid graph, the node type will be GridNode. Both of those type inherit from GridNodeBase, which in turn inherits from GraphNode.
GetNearest works for all graph types, so it has to return their common base class. If you want to do different things for different graphs, or if you know you only have one graph, then you can cast it if you need to.