Map Maker

A project showcasing my ability to make useful custom window editors in Unity

This is a BMP file from the game Hearts of Iron IV - a game (and mapmaking technique) I wanted to emulate

What inspired this?

I have long enjoyed Real-Time Strategy videogames such as Hearts of Iron IV and Stellaris, Frostpunk, and Kingdoms and Castles. However, their development eluded me. Creating a map with tiles always seemed to sacrifice performance, and wasn’t very extensible or easy to use for designers. It wasn’t until I truly separated the data from the view model that I was able to make an adaptable, useful tool.

If you just want the abridged version, this is an in-editor tool to rapidly develop extensible and performant levels or maps used for tile-based games. Rather than dedicating whole scenes and gameobjects to “levels,” game designers can use this tool to rapidly develop scriptable object “map”  files with an understandable interface. 

The Problem:

Early renditions represented grid tiles as whole Unity gameobjects or repainted a single subdivided mesh over and over again. Authoring the data (such as buildings and pieces on the tiles) was even worse, requiring monstrous and laborious editor scripts. While serviceable for a prototype or “one-off” project, these weren’t performant or extensible enough to serve as the foundation for a real game. I kept wondering, how do real developers do it? 

"How do real developers do this?"

Most big-name studios like Paradox Interactive obviously won’t sharing their trade secrets on the internet, and Youtubers and indie devs usually don’t venture into this niche of games. Thus, finding information on the proper development of maps, grids and various tile-based systems is pretty hard to come by. However, by going on Youtube deep dives and finding several infrequently visited forums online, I was able to sketch out my plan for a proper system:

  1. First, the concept of tiles must go from AoS to SoA. While harder to work with, this setup offers incredibly valuable performance. This is because most of the time, game computations need only 1 subsect of data from the tile, (say, the victory point value of each to calculate if you are winning) and dragging the whole tile struct along from RAM to CPU is wasteful. Thus, I will have arrays that I index into with the tile number, such as victory points, buildings on the tile, etc., and not one array of tile structs with those properties. 
  2. Separate immutable data (this tile is a hill, this tile is next to these tiles) from meta data that changes during gameplay (there is a factory on this tile, there is a unit on this tile).  This simplifies authoring from many fields to just a few, allows for smaller save files, and moves immutable data to another place to allow parallel work. This also makes for smaller save files.
  3. Automate the “boring” concepts like tile existence and tile adjacency by using a texture reader, and present a simplified edit view with QoL features by making a custom Unity editor window. Actually seeing, clicking on, and highlighting tiles of a map and changing their metadata fields is leagues better than editing a CSV file and hoping it looks right when loaded. Additionally, because my custom editor window uses reflection, future users of the tool only have to change a single script to give tiles the features they want. The tedious process of setting up editor scripts is done once and done right.

Left To Right: SoA script structure example. Separated assets for immutable vs. mutable data. MapLoader at work, detecting tiles and adjacencies. Blank map, automatically colored map from the recolorer tool, and maploader at work reading the BMP from said tool

The Results:

Now, I am happy to say I have achieved my initial goal of making an easy-to-use map authoring tool that can be readily incorporated into many projects. Combined with a texture subdivider and recolorer tool, I can take simple map outlines and turn them into high-performance RTS-style tile systems. I am excited to keep working on this tool, and to eventually make my own RTS-game!

Let’s code your imagination, together