Tag Archives: NavMeshSurface2DBaker

Progress Report: April 2019


This are the things I got done in April:

  • Finished savegame/loading refactoring (at leastf or now 😉 )
  • Thanks to the revised save system, I was now able to easily add some more things that get persisted in a save game and thus won’t be lost anymore when you switch between maps or load a save game:
    • Direction player character faces
    • Direction player ship faces
    • NPC ships on overworld map
    • Damage taken during ship fights.
  • Added a game over screen
  • Game now pausing overworld when opening the menu
  • The blog now runs with https, which will hopefully further improve the search ranking.
  • Fixed various bugs (walking animation bug,  ships sometimes vanishing just after spawning, etc.)
  • NPC ships can now be attacked in overworld
  • Made a big update for the NavMesh2DSurfaceBaker. This wasn’t needed for DotS but someone using the 2DSurfaceBaker asked for some new features. I’m happy something I made is useful to someone and wanted to support them as good as I can. Just listing this here since it took the whole Easter weekend and I want to give you an overview, where all my personal coding time went . Hopefully, this will also pay off for DotS in the future 🙂
  • Defeating an NPC ship now nets you some loot and allows you to return back to the map

Over all, I’m quite happy with the results. Since the player now can attack the spawning ships and gain some loot, we’ve finally got something resembling a small gameplay loop.
A thing I’ve long been waiting for and felt like I was “almost there!” for about a year now…


Currently, Unity only offers the ability to generate NavMeshes (the objects telling the path finding system where NPCs can move) from 3D obstacles. Since I’m developing a 2D game and would like to make use of Unity’s inbuilt path finding, this posed a problem.

That’s why I developed a solution that worked for my case. When everything worked, I thought to myself that it wouldn’t take too much additional effort to polish this a little, make it more multi purpose (e.g. I only needed it to detect polygon colliders and had no personal need for also handling circle colliders, etc.) and easy enough to use so it might be useful to other people as well.

What I ended up with is a solution to easily bake 2D colliders into a NavMeshSurface.

Supported colliders:

  • BoxCollider2D
  • CircleCollider2D
  • PolygonCollider2D
  • CompositeCollider2D
  • TilemapCollider2D (For those to work, you have to make them part of a CompositeCollider2D, though!)

You can find the end result here: https://github.com/SharlatanY/NavMeshSurface2DBaker

Here’s an example of a baked NavMesh for a hex tilemap (red tiles have a collider):

The project is published under the MIT license, so, you’re practically allowed to use it in whatever way you wish.

Unfortunately, as is often the case, I was very, very wrong about the effort it would take to make the project more useful to others as well.
Getting it to work for my specific use case took about a day of work, making it more general purpose, easier to use ,cleaning up the code, setting up the GitHub repository, adding instructions and a project example, writing this blog post, etc. took at least two more full days of work.

Now, I’m torn about how I should handle such things in the future.

On one hand, I’m really very happy to have made something that might be of use to others (I’ve seen people looking for exactly this functionality multiple times) and to give something back to the community. After all, there’s lot’s of people out there that helped me out in one way or another and even if it’s not always possible to pay them back, this feels like a way to at least pay it forward.
On the other hand, polishing and releasing this made the task more than 3 times as long as it would have been if I just stopped at the point where it was good enough for my own purposes.

If we’re honest, the project I’m trying to create is way out of scope and a monumental task that will still take me years to finish.
I only work on this in my spare time and when I feel like it because I know I’ll never finish it as soon as I have the feeling that I must work on it.
Currently, I’m on vacation and make quite good progress. But during the rest of the year, I maybe get to work on this project somewhere between 1 and 2 full days a week (likely closer to 1..) on average. Which means that making the NavMeshSurface2DBaker presentable and releasing it cost me about half a month of normal (=non vacation) development time.
With all the things that I already know still have to be done and the rate at which I discover new things that will also have to be done, I’m not really sure if I can afford and justify such escapades.