Ways to optimize a game built of cubes?

Hi

I have a game that is basically entirely built of cubes. The reason for this is because I simply want those simple graphics and need to store data for some of these cubes and be able to detect what cube it is that my player is standing on. But I then have the problem that the more cubes there are, the laggier the game gets. So the question is, how can I optimize the game to stop the game from dropping 30+ frames when I look in a direction with a lot of cubes?

I currently have a few ideas but I am not sure how well these will work. Any feedback on this ideas are greatly appreciated and so are new ideas!

Script to disable renderer when the object isn’t visible - The name is pretty self-explanatory. This would run on each cube and the player would tell all the visible cubes that it can see them and then they would enable their renderers. But if they can’t be seen they will be disabled.
I am not so certain about this because that would be a lot of scripts running at the same time.

Combining each type of cube into one mesh - So my game consists of different “cube types” and, in theory, that would allow me to combine all the cubes in a cube type into one mesh and it would still work. Again, not certain if it is a good way to do it.

(Hardest of them all) Building an advanced voxel engine - I could get or build an advanced voxel engine that would combine all the cubes into one mesh and then split that into chunks. I would be able to do that myself but then comes the part where I need to store information about some cubes or detecting what cube my player is standing on. So any help with that or an asset that allows me to do something like that would be great!

I would love to hear your feedback!

Having a MonoBehaviour on every cube, is a bad idea performance-wise. It would be better to cache all objects in a list and iterate over it from one central location.

Turning off objects, which are off-camera makes sense, if they have behaviour. Unity also has camera based occlusion-culling, which you can configure to only render what is on screen, so I would look into that.

And the best advice would be to combine everything into a single mesh. Then realize that you need more than the max limit vertices, so you split it up into chunks, which also works with occlusion-culling. I don’t think you need an advanced voxel engine, but basic mesh chunks and the right occlusion settings should take a big step further.

If you haven’t done so, google how Minecraft was made or even how clones in Unity work. There are some good resources.

1 Like

Combine it, your game could go from 60+ draw calls to less than 5.

Use the profiler and see whats slowing your game down. If its code, optimize, but I highly suspect all those cubes are slowing the game down alot.