2D TileMap chunk system help

Ok so I am trying to create a 2d TileMap(for terrain like in Civilization or Rimworld and other similar games) and want to go down the mesh generation route for the map. I can make a mesh from a 2d int array just fine. But there is a limit to how big one mesh can be so I have to make multiple meshes “Chunks” if you will, so the map can be larger. I found a pretty straight forward way of doing it but its not completely what I need. The system I found makes smaller int arrays and generates the mesh for the chunk based off of that. And then makes multiple chunks for the desired map size. But when it comes time to make the tiles in the map look like landmasses and oceans I cant generate the terrain over the whole map because there is no big array for the map. So I need to do the opposite of what I am doing now and make one large 2d int array for the map and generate chunks(separate meshes) from that one array. But I have no clue how to generate multiple meshes from one array. I have tried googling, looking through forums and everything I can find is for endless map generation. They use chunks for memory reasons and what not. But my maps wont be big enough to worry about loading and unloading chunks from memory. I just need them because of the limitations of unitys mesh system. Any advice would help, I’m sorry if this question is a little unclear. If you have any questions about what I am trying to do so it is more clear let me know. Thanks for you time.

Have you tried making an array of arrays? Using a List<> might help to organize a bit better.

Abstract out the management of the chunks, and the generation of them.

Make a single generic function that creates the mesh plane that you need for each chunks. Generate it, and store it in your chunk array.

Now to deform it, just a little math.

Let’s say you have 16x16 chunks, and each chunk is 32x32 vertices. That is 512x512 vertices overall. You can then use a 512x512 heightmap to deform the terrain. You figure out where in the heightmap to deform like so:

x = ((chunkIndexX * 32) + localX) - chunkIndexX ;
y = ((chunkIndexY * 32) + localY) - chunkIndexY;

This assumes you are using a two dimensional array for chunks. localX and localY represent the x and y position of the mesh (vertex position in vertices array really; this is making an assumption I detail further on) you are operating on.

There is a bit more to it though, as your chunks will have shared vertex positions along edges. This means vertex 32 and vertex 33 (31 and 32 index wise) share the same coordinate. This is why we also subtract the chunk index. In reality, your heightmap would be 498x498 (I might be slightly off with that).

Another thing you need to consider is that you will have noticeable seams along chunk boundaries. This is due to a lack of information regarding normal calculation. This means you need to be able to keep track of who is a neighbor with who, and on which side, so that you can manually fix the normals via Vector3.Lerp() for your edge vertices. Given two vertices that share the same position, you do this:

Vector3 newNormal = Vector3.Lerp(normalA, normalB, 0.5f);
normalA = newNormal;
normalB = newNormal;

Fortunately, you can use the indexes to figure out who is a neighbor of who, and which normals need to be corrected. Since you are generating the meshes yourself, you should know which vertices are on the edges. If you make your mesh from bottom left to top right order, you know the following array indcies:

bottom left = 0
bottom right = 31
top left = 991
top right = 1023

You can figure out which vertices are on which edge based on this.

TL;DR: indexes, indexes, indexes

Figured it out. I already had everything I needed just didn’t realize it XD Im following a couple tutorials and piecing together the information that I need from them into a hybrid type of what each one does. I just wasn’t clear exactly on how they were handling this in the tutorial and now I do. Thanks for the replies. Much appreciated.