- Home /
Combining meshes multiple times.
Hey guys! I wanna ask, that how to combine children of a gameObject with no material change, or at least other solution. I'm developing a game when player can destroy block, kinda like in minecraft, and I'm creating trees right now, and I ran into a problem, that drawcalls go mad, even with a single tree. So how should I combine the meshes parented to a object, without loosing the material and being able to destroy the parts of the tree? Because I have different material for bark and for leaves, but when I combine them It simply uses the parent's material. Or should I use another method?.
Answer by Waz · Jul 10, 2011 at 11:26 PM
While Minecraft may look simple, the "obvious" approach of just drawing lots of cubes will have exactly the problem you describe, in addition to a big danger of massive overdraw. You'll need to be pretty inventive to make it efficient.
One answer would be to separately model a tree as both a full tree (combined), and a partially destroyed tree (as a colllection of cubes), then replace the former with the latter the first time it is damaged, on the assumption that most trees will either be completely untouched or completely destroyed, with only a few in the inefficient collection-of-cubes state.
I doubt Minecraft uses that approach though - it appears designed for arbitrary cubes and for that, I think the only solution would be a custom mesh engine. The closest you'll get to that with Unity is to modify the mesh from code whenever it is damaged.
Well...I tought about it for a bit, and I found out, that the main think, that makes the trees slow is the rendering..So I could make it like having only cube colliders, and one big mesh as the whole tree, which would I remake when a collider is destroyed. But I have a bit problem with remaking the mesh, because I can't combine the materials. When I combine the meshes it uses the parent material, and moves the mesh downards.
--$$anonymous$$
$$anonymous$$esh combining is just code, nothing magic. If you don't like the way the one Unity provides works, change it.
Well... I tried the script, that's on the docs.. $$anonymous$$aybe I'll hardcode, that it always moves the tree upwards, and than I make a atlas to the texture... But still thanks fro answer.
Your answer
Follow this Question
Related Questions
Simplest way to have a damage decal or texture on cubes. 0 Answers
Combine material's main texture and main color 1 Answer
Minecraft style grid and block placement? 2 Answers
How to create a Grid System (Multiple Questions) 0 Answers
How do I assign different parts of model to different materials during runtime? 1 Answer