I want to create a grid based building game. The way I first started developing it is by creating a base tile class with a basic plane/static mesh component. Once the class instance is spawned into the game, it saves its location into an array. I later than want to use the locations from the location array to recognize each tile and place buildings on top of them.
An example of the idea is on the image below, just on a smaller scale. The small squares are instances of the base tile class, the larger ones are biomes:
Example of how it looks when spawned into the game:
The way I did it in the first version is by having a MainGrid class that spawns the GroundPlatform class in regular intervals. The GroundPlatform class then spawns the individual TerrainTiles. The reason I did it this was I so that the GroundPlatform base can then be a separate biome and spawn different TerrainTiles for different biomes. The problem with this is that the way the locations are saved into the array is sorted by biome, so if I want to build a building in between 2 biomes, finding the location will get more complicated. Also, I use the spawn actor from class to spawn the Terrain tiles in.
Representation of class division:
The image displays the spawning in of the terrain tile class instances and saving the locations to an array (SpawnTIle is a blueprint implamentable event that calls the SpawnActorFromClass blueprint function):
The way I created the first version I didn’t really like since it has problems that could get annoying later on, so I tried to create a second version. In the second version, instead of an array, I used a TMap. As the key, which in my case is more of a way to locate things easier, I used a similar way of location names as on a chess board. In my case the first row where X=0, the key starts with the letter A and then 0-10(or whatever the row number is), the second row then starts with the letter B. For Example the tile that is third in the first row should then be A2. The second thing the TMap variable saves is the location of the individual tiles.
I still haven’t fully tested this, but I think it should look along the lines of this:
The variables are saved like [this] .
Now my question are:
- is there a better way to do grid based worlds in Unreal Engine?
- Should I even save the locations, or is there another way?
- Is TMap the best variable type to save the locations, or is there still a better way, if I want to have building mechanics and potentially even turn/grid base unit movement?
- I could also potentially have both, the first version to spawn and the second to save the locations, but to me, it feels like I have more processes than needed, should i just combine them anyway?
- Is spawning things in using the spawn actor from class even the right way to do it if I want to have randomly generated worlds?
- Is there a reason many strategy games use hexagon shapes for movement?
- Is there something I have to watch out for when trying to create larger auto generated worlds?