What would be the best way to add new type of height check to a grid graph?

I need a custom height check (basically, 5 rays instead of one, with averaging of hit heights; this is because the underlying collider is not aligned with the grid, so a cell can be e.g. divided diagonally, with a deep drop on one side, but still have “ground” in center, so the usually height check will mark it as walkable, which will look badly at runtime).

I can run a PostScan step that will do additional raycasts, and set/clear Walkability flag + add/cut connections depending on results, but this feels somewhat wrong.

Check out the Writing Custom Grid Graph Rules page. Looks like this is what you’d want? Let me know if this isn’t it :+1:

1 Like

Sounds promising! I haven’t thought of writing my own Rules. I’ll check this out, it seems this approach should work for my case.

1 Like

Thank you, it worked. GridGraph rules are an interesting addition for sure. I think I need another rule, but I’m not sure which Pass it can use: after all areas are calculated, I need to make nodes belonging to some of them unwalkable (basically, I want to eliminate accidental “islands” that are never really reachable; I have some additional information that allows me to do that).

In 4.x, this was done as an additional code after scanning the graph.

In 5.x, it seems that this can be done in Rule in PostProcess pass, but the manual explicitly states that I should not modify walkability there “because connections will not be up to date”. But since I’ll be removing whole areas, so I don’t care about connections. Still, it bother me. Or maybe I shouldn’t use Rule for that? I can simply add a GraphModifier (I need one, anyway, for other reasons) and do this in LatePostScan?

My favorite four words to hear when I’m responding to questions here :relieved::relieved:

This has come up a few times- the islands problem. This thread here has some solutions that have helped other users.

It seems that the linked thread tries to solve a different problem, and I’m not really seeing how it is related to mine. It mostly deals with the question of removing nodes already marked as unwalkable from a Recast graph, which is not what I’m trying to do. I can’t remove nodes (since I’m using a GridGraph), but I need to mark them as unwalkable, despite the fact that they passed all previous checks.

To do that, I’m using a kind of “probe” components that are added to all possible entrance and teleport points on location: I check which Area ID are located under my probes, and remove nodes whose Area ID don’t fit this criteria. This works pretty well. I just need to find a good point in the pipeline where I can actually do that. As I said already, GraphModifer’s LatePostScan seems to fit the bill, but maybe Rule’s PostProcess pass does, too, if I can actually somehow modify walkability during that pass.

If you are trying to use the Area property of each node, it won’t be available when the rules are calculated, I’m afraid. This property is only calculated after all graphs have been scanned.

You could do a flood fill yourself and calculate the connected regions, I suppose.

In that case I would recommend doing it in the PostProcess pass, but also recalculating connections after you are done using the same code that the grid graph uses to calculate connections:

context.data.Connections(graph.maxStepHeight, graph.maxStepUsesSlope, context.data.nodes.bounds, graph.neighbours, graph.cutCorners, collision.use2D, true, characterHeight);

Note that you should use graph.data.walkableWithErosion, not graph.data.walkable at this point, since all of this runs after the erosion pass.

Sorry about that by the way, I totally jumbled the words I was reading! The dangers of doing tech support before the coffee kicks in…

Thank you everybody. I decided to place this code in OnLatePostScan of my GraphModifier, and it works well enough.