How to programatically create a level from an input file?

All the tutorials that i’ve seen so far have me creating some kind of level in the unity editor. That’s great, but i’m hoping someone can point me in the right direction for either documentation or any kind of learning training/vids/etc on how to generate a level using some kind of tile asset from an input file.

e.g. in a nutshell, imagine a level that is a 100 x 100 grid. i’d like to be able to purchase a tile asset package from the asset store such as one comprising of a dungeon. Then, would like to be able to generate levels from an input file (ascii text is fine or anything really) where the input file specifies what tile should be in each of the grid’s 100 x 100 cells. Then start the game on that programatically generated level. In essence, supporting the ability to easily generate new levels (perhaps player generated) or even programatically generated randomized levels.

is there anything someone could point me to that would help me learn how to do such a thing?

I recall searching for this kind of thing when I started Viking Chess a year and a half ago. I don’t think I ever found one particular resource that was exactly what I was looking for, but I ended up finding bits here and there that led me in the right direction.

Bear in mind, the file I’m loading are for much smaller grids. Biggest I’ve done is 13x13, so I can’t speak to how this will perform when scaled to larger levels.

I load the text file as a Unity TextAsset, and then split that into a string array (using Split(“\n”[0]) ). I then loop through two counters representing the board’s X and Z, and grab the appropriate character at each location. That character determines whether it’s an empty tile, or some type of piece.

I know that’s kinda general, but the specifics of what you’d do would greatly depend on a lot of things.

2 Likes