Minecraft style game is really laggy

Hey i was wondering if anyone would no a good way to go about optimizing a minecraft style game. I have already set up the noise so there is hills and an inventory system with multiple blocks and stuff but if i go into the game with the depth of the terrain set to one so if i dig down one block you can fall out of the world it runs pretty well since there is not that much on screen but is i start making it 4-5 blocks deep it is unplayable. I am using hierarchical instanced static mesh and have set it to be an occluder but it is still laging is there a way to make it that only visible faces are shown or something. Anyone have any advice.

it depends very much on the game mechanics you have made. a trivial approach seems like starting with all blocks disabled, and then enable these that in range of the viewer. it can be an intense task for calculation because there are many blocks and checking each one will be very hot, so you may adopt original minecraft rendering tactic, in which the blocks are arranged in chunks, and these chunks are loaded instead of single blocks.

Thanks for the reply but i forgot to mention that i do already have a chunk system made that loads in the chunks within a certain distance. The main problem i think is that the blocks underground are being loaded witch is making it very hard to run. I am loading in all the blocks with a couple for loops spawning blocks along the X Y Z for each chunk so if i change the Z to say 2 there will be 2 blocks when you dig down and that works petty good but when i start to change it to 5+ blocks deep it is very laggy but if i make it 10+ blocks deep the game crashes and gives me an error saying it found an infinite loop.

that’s why you have to unload these blocks that you don’t see. then upon every time a block is getting destroyed, call an event, which loads the missing nearby blocks. it is up to you to initially load all the visible blocks though. there are many algorithms to make it and i can’t supply a way for it in comment because it is too much work for a forum answer.