Removing isolated areas

Hello,

On my map i have a complex surface so my grid graph have some isolated zones (some walkable nodes surounded by unwalkable, like on screenshot). So have there some magic checkbox or code solution to remove this areas (mark them as unwalkable) ?

https://drive.google.com/file/d/0B9LhACTRtuBDMVJ6bDBTdUNsRUU/view?usp=sharing

Thanks.

Hi

Not out of the box, but you can do something like this

AstarPath.RegisterSafeUpdate(() => {
    // Count the number of nodes in each area
    int[] sizes = new int[200];
    var gg = AstarPath.active.astarData.gridGraph;
    gg.GetNodes(node => {
        sizes[node.Area]++;
        return true;
    });

    // Find the area with the highest number of nodes
    int largest = 0;
    for (int i = 0; i < sizes.Length; i++) largest = sizes[i] > sizes[largest] ? i : largest;

    // Make all nodes unwalkable that are not in the largest area
    gg.GetNodes(node => {
        if (node.Area != largest) node.Walkable = false;
        return true;
    });

    // Recalculate all node connections
    gg.GetNodes(node => {
        GridGraph.CalculateConnections(node);
        return true;
    });

    // Do a flood fill to recalculate the Area fields
    AstarPath.active.FloodFill();
}