Inverted masks for recast graph

Hi, I can’t figure out one issue with the Recast graph. There are a lot of tools to cut out a piece of the Recast graph navmesh inside specified objects or to add navmesh, but I haven’t found anything that removes navmesh on the outside selected objects, that is, using objects as a mask to define where the navmesh should or shouldn’t appear. The thing is, I need to make async rescan the recast graph at runtime every time I update masks (for example once in a minute), and the level’s structure makes it easier for me to mark where the player can walk rather than where they cannot.

I was considering a couple of solutions, like a black-and-white RenderTexture that triggers an Async Scan when updated, or a set of mesh masks that cut off everything outside them during baking. I looked for such methods, but unfortunately didn’t find anything. So I’d like to know, may be I missed something, could you please suggest a way to implement something like this? I know grid graph supports texture masks, but I specifically need Recast.

I think you may get some use out of the RecastNavmeshModifier

According to the description

Using the RecastNavmeshModifier component you can:

  • Exclude an object from the graph’s scan completely.

  • Ensure an object is included in the scan, even if it would normally be excluded.

  • Make the surfaces of an object unwalkable.

  • Make the surfaces of an object walkable (this is just the default behavior).

  • Create seams in the navmesh between adjacent objects.

  • Mark the surfaces of an object with a specific tag (see Working with tags).

But looks like I can’t use it as inverted mask to include in the scan the surface area only inside the object with RecastNavmeshModifier, right?

I’m realizing I neglected to post my thought process for why I suggested that! But actually I want to confirm my thoughts before I suggest it just to go from 95% sure to 100% :+1: Gonna test it out now.

Nope! I was almost correct– I couldn’t scan “something from nothing” like I thought, even with RecastNavmeshModifier. Been down a bit of a rabbit hole looking for options, but I think you could just use a RecastNavmeshModifier and tags, maybe? And then mark everything else as not walkable, if you really need it, which is as simple as this:

var graph = AstarPath.active.data.recastGraph;

graph.GetNodes(node => {
    node.Walkable = true;
    if (node.Tag == 0) { // Default tag becomes unwalkable
        node.Walkable = false;
    }
});