Last time I talked about the fight I was having with Unity’s built-in NavMesh system, trying to get it to generate a bit of a more complex mesh than it was really designed for.

At the end of that post I was working on a script that would automatically split my terrain into layers based on slope, so I could hopefully then assign those as different layers in a NavMesh. I finished that script and it actually turned out quite nice.

Now from that, I could finally generate a nice layered NavMesh in unity:

Slow vehicles can stick to the blue area, more powerful vehicles can include the purplish area in their path calculations, and almost everything is covered by NavMesh so targets outside both areas can still be pathed to. Basically what I wanted last week but couldn’t quite get. Static obstacles still have gaps around them but that’s not a big deal. It’s almost too good to be true…

So of course it is. As soon as I try to calculate a path with it, Unity crashes! Is there no end to these sisyphean trials? It seems like the extra detail generated from the layer joins is just too much for Unity to handle (although I notice that the actual path calculation, when it occasionally works instead of crashing, is still very very fast. So er, C+ for effort Unity).

A couple of people mentioned the A* Pathfinding Project as an alternative option after my last post, which I’d seen before but not really looked into. It seemed like an opportune time to give that a look.

In summary it basically looks good. It gets around some limitations in Unity’s built-in system by allowing 3D model meshes to be used directly as navmeshes (Unity only allows generating navmeshes based on meshes), and not crashing when you use it is a nice bonus. But its interface and API is quite different to the built-in Unity one and it’d require a bit of time to convert things over – and this whole process has already been way too time-consuming!

So I simplified the Unity NavMesh to a point where it has as much coverage as possible while not crashing.

THAT’S GOOD ENOUGH.

Sometimes it’s all about knowing when to stop and move on.