GraphUpdateScene With Tilemaps Issue

In my turn-based roguelike project, I’m using GraphUpdateScene with tag penalties to get my NPC to determine whether they should walk through or around tiles on a specific tilemap depending on the penalty assigned to that tilemap. The water in my game will be traversable, but will have a movement penalty. GraphUpdateScene uses the bounds of a tilemap to determine where to apply penalties, but this has the effect of empty areas in between sections of water still being treated as water.

As you can see in my screenshots, the NPC should be walking in between the bodies of water, but instead wants to walk all the way around. One solution would be to break up each body of water onto a separate tilemap, but that is far from ideal and would be quite messy to deal with. This also doesn’t account for abnormally shaped bodies of water, as the tilemap’s bounds are always going to be rectangular. How can I just say, if this tile is water, give it this penalty, if it’s ground, give it no penalty?


I just got rid of the GraphUpdateScene altogether and instead iterated through each node and manually assigned the tag based on the tile’s type:

Vector3 gridOffset = new Vector3(0.5f, 0.5f);

void Start()
    {
        // Update tags of each node
        GridGraph gridGraph = AstarPath.active.data.gridGraph;
        for (int y = 0; y < gridGraph.depth; y++)
        {
            for (int x = 0; x < gridGraph.width; x++)
            {
                var node = gridGraph.GetNode(x, y);
                SetTagForNode(node);
            }
        }
    }

public void SetTagForNode(GraphNode node)
    {
        if (GetTileFromWorldPosition((Vector3)node.position - gridOffset, shallowWaterTiles) != null)
            node.Tag = 2;
        else
            node.Tag = 0;
    }
1 Like