Hey!
I’m new in this forum, hi everybody
I’m making a game (RST game) style minecraft, a world made with cubes, and I have a problem with the performance. The problem is, for example, a world with 200x200x100 cubes (simple cubes with simple texture, size 1x1x1), the RAM is full and the camera moves so slow. I’m looking for a solution for this issue, like only render the cubes you can see or something similar.
An example that what I’m talking about.
There are a lot of topics on this, and similar posts in the forum. The TLDR version is: you can’t render 4 million boxes and expect good performance, and there’s no easy built in way to cull ones you can’t see efficiently.
The primary solutions are:
Greedy meshing - Generate a unique mesh on the CPU that is just the external features of the voxel data.
Custom GPU instancing - Unity’s built in GPU instancing is fairly heavy and does way more than you need it to. Instead you need to write a custom instancing setup that only stores a position per-cube instance and render them manually via Graphics.DrawMeshInstanced or similar commands. You may still need to cull the interior instances, but again you’ll need to do that yourself.
Thanks for your reply!
Obiously the machine can die if I try to render 4 million of boxes, hehe, that’s my problem, how to show them.
The idea is you can dig this blocks, I can’t use a unique mesh, the player can destroy blocks one by one (as minecraft, more or less), that’s why I’m looking an idea to solve the problem.
One idea is desactivate the blocks inside and, when one face has no block at side, show them, but I don’t know how to implement this (how to know the nearby blocks. An constinious update showing and hidding blocks I don’t think the best solution to this…
And by that I mean a 3D array of data that holds information about every grid position in your game scene, not “it looks like minecraft”. Then you’re only going to be drawing / building geometry at the boundaries between where that data says there’s something, and where there’s nothing, not trying to render a cube at every point in the grid. And you do that mostly by brute force iteration through the data.
Basically, if you try to make a minecraft game where you start by just put down a big grid of cube mesh game objects, you’re going the wrong way and you need to delete all of those. Search for some tutorials on “making minecraft in Unity”, and if they don’t have a section talking about 3d data structures and mesh generation, try another.
There are assets in the asset store that will help you with this, like for example this one: https://assetstore.unity.com/packages/tools/game-toolkits/voxel-play-2-201234 (note: I haven’t tried this particular one and there also might be better options in the asset store - but this is a problem that many devs have already solved, so you might find good solutions in the Asset Store)
Thanks a lot (both), I’m learning about this and the concept to develop this is completly diferent what I thought.
I’m going to check this asset and see if is good for my proyect.
Thanks a lot!