Alternative ways to store Tile data

So I am making an infinite tilemap, and I am thinking of different ways to store the tile data. Currently I have a bunch of scriptable objects in the resource folder being loaded in at runtime. I feel like this isn’t the most optimal solution. What are some different ways to store this type of data that is accessed so frequently?

EDIT: Just to clarify, I am not looking for in depth examples or anything. I just wanted to get a general sense of what other options there are :slight_smile: I can figure out how to implement them on my own.

Can you provide more details?

Are there more tiles than will fit into memory all at once?

Is the topic about storing individual tile resources or the instantiated tile map?

Is it like an infinite runner where you can discard parts of the map that the player has left behind?

I sure can! I am sure all the tiles could fit into memory, I just wanted to find a nice efficient way to store them. I am looking just at the tile resource itself, the tile map is infinite. Think a game like advanced wars, but the map goes on forever. I have thought of creating all the tile classes at runtime and storing them in a dictionary, or something along those lines so I can create them in code rather than in the editor. Unless storing them as assets in the editor is a good solution to begin with. I am sure there are many options and I just wanted to get an idea of what all options are out there :slight_smile:

Interesting topic! How do you plan to select tiles when building the map? Are there rules to specify which tiles are allowed to connect to other tiles? Or perhaps rules about how to distribute tiles with different properties? If so, and if you have a lot of different tile types, you’ll probably want to store these rules in a way that’s efficient to access when building the map.

All of that, I am not sure of! Still learning about procedural generation. Just wanting to know all my options for storing the data for each tile. Not the in game tile, but rather the data for the tile types (plane, hill, mountain, city). The tilemap will be stored via a seed.

Like everything else (graphics, multiplayer, AI, etc.), it’s all about data management, isn’t it. There are two facets of data management, often in opposition: how humans work with the data and how algorithms work with the data.

You don’t want your algorithm to loop through the entire tile list every time your procedural generator needs to select a new tile for the map. If you only have a few tiles, this might be fine. But if you have hundreds of tiles it could really drag down performance. Depending on your generation algorithm, each tile could have references to other tiles that are allowed to connect to it, with conditions and/or probabilities. You could even have an additional data structure that defines the general attributes of a region larger than a tile, such as a choke point made of a 9x9 block of tiles that meet certain criteria. It takes a little more memory to store this metadata, but it can make it faster to generate maps on the fly.

All this would be a major pain for you to define by hand. You could write a preprocessor to generate that tile metadata based on attributes that you’ve set up. For example, say you’ve defined a Mud tile with this metadata: movement speed 50%, connects to the same type of file 60% of the time, connects to an open tile 80% of the time, contains a monster 5% of the time. Your preprocessor could automatically find all other tiles that meet these criteria and add it to this tile’s list of possible connections. If that’s too much data, you could instead generate lists by attribute (e.g., open tiles) and reference those lists instead.

I like to manage data all in Unity when possible. A custom editor would be great for this, either a custom editor for your scriptable object class or a more general editor that lets you manage all of your tiles in one window.

However, you can probably find plenty of people who’d prefer to manage the data in an Excel spreadsheet. You could have a row for each tile. Then just export it as CSV and process it to generate your tile metadata.

I have a question: when you say you have a bunch of scriptable objects, are they all using the same script? Have you considered using prefabs instead? They’d probably work really well for this. In either case, I recommend pooling your objects. Don’t instantiate scriptable objects or prefabs when you need them. Instead, keep reusable pools of instantiated objects in memory instead.