Build a Resource when starting the game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Eleos91


i want to make a tile-based game and the tiles have certain properties called TileType. So i inhereted Tileset with an additional Array which is basically a function from tile id -> TyleType. A TileMap script is iterating through the used cells and building a Dictionary which is a function like tile coordinates -> TileType. This works quite fine and allows me to make changes on the map and the TileTypes are always correct, but it seems unnecessary to build this tile coordinates -> TileType Dictionary at run-time.

Is there a way to build a Resource when the project is run/build? If so, the dictionaries only need to be build once and are instantly accessible for every map.

PS: Why is mother a sugegsted tag for my issue? That’s super weird…

:bust_in_silhouette: Reply From: spaceyjase

Yes, you create a custom resource that manages whatever information you need and assign it to the classes that require it.

That said, aren’t you essentially duplicating the information in the grid? i.e. the tile map is the information that’s built in the editor. You just need to provide a wrapper around this; putting it in a dictionary is essentially duplicating information (and thus memory).

Thanks for the answer but:

  1. my question was if the resource can be made when i run the game in the editor or build the game

  2. retrieving the information from the tile itself is more computatinal heavy, because there has to be more references followed and i don’t know how the information is alligned in the memory and i have to get to the tile type very frequently. Sure, that would double a couple of bytes, but with the additional resource, i can allign the information in a way, that less references have to be followed and the tile types are are in sequence in memory, leading to less cache misses and stuff. That’s a good trade

Eleos91 | 2021-12-19 10:44

I guess you could derive a custom node (or plugin) from the tile map and use your new type as a drop in replacement, if that makes sense. Possibly, sure!

spaceyjase | 2021-12-19 11:11