Blog

Baking Unity NavMesh with Box Colliders

January 10, 2014 by Devin Reimer

Up until recently in Dyscourse we had been using a pathfinding solution called “A* Pathfinding Project”. While it was a pretty impressive tool we weren’t happy with performance and some of it’s complexity. So I decided to give Unity’s built-in NavMesh a try.

Unity’s NavMesh worked pretty good, but it had one big issue, it didn’t support baking Box Colliders into a navigation mesh. It only supported MeshRenderers and Terrain. In Dyscourse we have a 3D world but everything is flat 2D planes, so this simply wouldn’t work.

Not deterred, I ended up figuring out a work around and created an editor script to do all the heavy lifting. This script automatically bakes Box Colliders into the navigation mesh with the press of a button.

Download NavigationHelper.cs (right-click save as).

To Use:

Simply put this script into an ‘Editor’ folder and add a new Tag into your project called: “TempNavMeshItemDestroyable”.
Run by going to Windows->Navigation Helper and then click ‘Build NavMesh!’. Everything happens automatically.

As an additional option in the script you can edit the COLLIDER_LAYER variable and set it to a layer you want to filter Box Colliders to.

3 Responses to "Baking Unity NavMesh with Box Colliders"

  1. Fluzing says:

    Will this work with Unity 2D mode?

  2. Gabriel says:

    Hey, I just downloaded and this was all I needed!!
    Thanks a lot! Great work!

Leave a response