Excluding deep water from RecastGraph

  • A* version: 5.4.4
  • Unity version: 6000.0.049

Hello,

I’ve got a large world (8x8km) that’s using a single RecastGraph and a ProceduralGraphMover that follows the player. I’m attempting to implement rivers and lakes, and I want to ensure that agents can path through shallow water, but not through deep water. Water can be of variable depth, and is at various elevations across the world - flowing down hills, etc.

I’ve had success in doing this via a very naive OnPostScan() callback that adjusts the node.Walkable property based on a raycast upwards from each node. If it hits the water plane, but the water plane is more than 1m away, it marks the node as not Walkable.

Unfortunately, this dumb approach costs 20fps on some consoles, as it’s performing ~15,000 raycasts every time the ProceduralGraphMover updates (it’s scanning the whole graph, not just the boundary tiles)!

I could try to batch the Raycasts into RaycastCommands, but I figure there must be a smarter way. I’ve spent the day trying to dig into the guts of the RecastGraph, trying to see if there was any way to add a custom Rule or inject a raycast at an opportune moment. I found this topic, which looked promising, but it didn’t seem like a Job was exactly the right place for what I needed.

Is there a better place I should be looking? Thanks in advance!

I think you’ll want to look into tags for this. If you’re able to tag places x meters below the water level as deep water you can simply use tags to make it unwalkable.