- Home /
Combining meshes for independently moving objects
Is there a way to combine meshes on child objects when the child objects can move independently of one another?
Let's say I have four walls that all share the same material. I can make them children of a single parent object, apply the CombineChildren script to the parent, and get a single draw call instead of four.
But now let's say one of the walls needs to move. If I move one wall in the above scenario, the auto-generated mesh doesn't update. Is there any way to solve this?
Answer by duck · Apr 23, 2010 at 07:57 PM
Unity iPhone has support for this, and it happens automatically if models share the same material. It's called dynamic batching.
This isn't present in regular Unity however.
Edit: This has now been introduced for all platforms in Unity 3.0!
You can read about dynamic batching in the Manual here: DrawCall Batching The most important thing to note is that dynamic batching only works for objects which have fewer than 300 vertices.
An interesting alternative to this is that it's actually possible to achieve this using bones.
Have a look at MikaMobile's great explanation of it on this forum thread where he describes animating a set of billiard balls as a single mesh (and hence 1 draw call), with each ball controlled by a separate bone.
Also, using a skinned mesh with bones is more efficient than dynamic batching anyway, since dynamic batching has computational overhead every frame and is limited to 300 triangles per independent object (because otherwise the overhead would overpower the savings from reduced draw calls).
Answer by Eric5h5 · Apr 23, 2010 at 08:51 PM
See CombineChildrenBones on the wiki for one method of combining objects into a combined skinned mesh with bones, although it could be improved. (The note on that page about being slower than separate draw calls is either due to an older version of Unity iPhone, or something to do with the script, because my own observation of skinned mesh usage is that it's distinctly faster than both separate calls and dynamic batching.)