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.