- Home /
In Game level builder - Combine Mesh? Or Stick with Cubes?
Hi All,
I have been working on a prototype for a couple of weeks now, and I have a basic system that let's me snap a door to a wall of 1x12x1 cubes that disable rendering to put a door in place of the wall.
This feels very inefficient, especially if I have the user create more walls that are a bunch of 1x12 rectangles. Is there a more efficient way of doing this? I see articles of using Combine Mesh, but I don't see a way of taking the mesh apart after it has been combined. Taking the point where I create a wall, and its combined but then want to put a door on the wall.
I could also be looking at this all wrong. What has been your experience in building maps at run-time?
Answer by toddisarockstar · Oct 03, 2018 at 03:43 AM
if proficiency is your worry, the way the meshes are combined or parenting shouldn't make much difference. one thing that could slow you down is the amount of faces.
if you are building with cubes and you have a big flat wall of cubes. the video card needs to process each cube's faces individually. if you are planning to build large levels, this puts strain on the Video rendering and slows down FPS.
instead if you scale one cube to match the height and width of the wall, then set the tiling so the texture repeats, you could have an identical wall and the video card only needs to render one cube and you will render much much faster.
remember size/scale doesnt matter when rendering info is sent to the video card. a small cube takes the same effort to process as a large cube.
This is a problem i found making my last level generator when levels got big.
you should consider an algo to detect and replace the long strait walls with single streched cubes.
if you want help with how to setup an algo for something like this let me know
This answer is actually misleading. The number of faces is actually not that much important. Of course the more faces the more work has to be done by the GPU, but it can process millions of triangles without any issues. However seperate objects is a real problem. Seperate objects require seperate drawcalls / SetPass calls unless it can be batched. Though static batching only works for objects that never move and are marked as static. Dynamic batching has a lot restrictions and only work for very small object (only a few vertices). Dynamic batching als gets very inefficient if you have a lot objects. It's generally more efficient to have a few large meshes with just a single material than having many small meshes with many different materials.
Replacing long strips of quads with a single one doesn't really help much and is just way too complicated to work out. $$anonymous$$inecraft for example renders every cube face as a quad. Though it works on chunks of 16x16x16 cubes which form a single mesh. Rendering seperate cubes or even faces would totally kill performance. The bottleneck is the CPU to GPU bus if you have too many seperate drawcalls. Also setpass calls are quite slow. So having many different materials require to change the shader / shader parameters between the draw calls. That's why it's more efficient to use a single material with a texture atlas.
Your answer
![](https://koobas.hobune.stream/wayback/20220612175645im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Export objects to a .3DS file at runtime 1 Answer
Game runs painfully slow in Unity 0 Answers
WWW.texture vs WWW.textureNonReadable 1 Answer
Overwriting a prefab in runtime? 1 Answer
Problem with texture swapping at runtime (Android only) 0 Answers