Most performant way to do a tile based 3d game?

Hey everyone,

I want to do something similar to what stardew valley does with people able to interact with a specific tile of the map, such as planting a seed on a certain tile. I want to do this with a 3d game though. What is the best practice when it comes to building 3d tile based maps? Thanks!

Do you need a 3D grid?
The grid is usually just the ground plane and is a 2D grid(unless you’re doing voxel terrain like Planet Coaster/Zoo), in my game (3D and has a 2D grid) i put on each tile an “elevation” variable and that what makes it not flat in rendering and in the movement logic and etc.

I want something like animal crossing where everything is grid based but I don’t know how I should go about doing it. Should each tile be a separate object? I feel like there would be thousands of objects if I did it like that.

I have a grid that can reach over 2 million tiles(highest tested is 1,950,000 but i’m sure it can go a lot more), they are all just C# classes in data, all each tile needs as a basis is 2 ints for the coordinates, that’s not a lot of data at all.

even in my case I have a lot of data on each tile,
coord(3 ints, axial hexagon coords), elevation(byte, highest value is 127 so I don’t need to waste 4 time the space on an int), water level(same as elevation), humidity(float), salinity(float), and that’s just a few, the data itself doesn’t take all that much room and this days you can take up a really liberal amount.
To give some figures about my game as an example, the whole grid, plus 5 million plants, plus 100k entities walking around on a A* representation of said grid takes up less than half a gig, rendering a small area of that world costs me 2 gigs.

what you need to do is cull and batch the rendering.

Also, I don’t know animal crossing (only heard of it, didn’t play it), so you might wanna explain what it does that you’re after, even if I did know the game.

Basically you can plant stuff, or drop furniture which are grid based actions.

Is batching automatic as long as I have the tiles set to static?

What I meant by batching and culling is that if your grid and tiles are plain C# objects (NOT monobehaviours in the scene) you can visually represent many tiles with one object and not render stuff that are out of view.

Can you explain a little bit about plain C# objects and not monobehaviours? I understanding culling but I’m not sure what you meant by C# objects.

I mean just a C# script that is not a monobehaviour, not sure how to explain it more.

public class Tile {

}

VS

public class Tile : MonoBehaviour {

}

most the functionality the monobehaviour provides can be routed though a manager script (excluding stuff like OnCollision, but you shouldn’t need it here imo)

The advice of @SparrowsNest is solid but also probably a little overwhelming. If you don’t need an endless, streaming world then things can get a lot easier. I’m fairly certain Stardew Valley works in maps, in the sense that you exit one area and enter another.

A 2D grid and a 3D grid are functionally the same. You can convert world positions to grid positions by dividing by the size of your tiles. As for drawing, if your world is small enough without a lot of height variation, then having a few thousand GameObjects representing each tile is probably OK – you can also get your feet wet and start with drawing them via Graphics.DrawMeshInstanced() and optimize from there.

2 Likes