- Home /
Why is constructing a cube from 6 faces so much slower?
I'm drawing a couple hundred cubes and nothing else, and decided that I'd like to be able to control each of the faces of the cubes. What I've done is create an empty GameObject for each cube and then use it as the parent for each of 6 face GameObjects. Doing so has rendered the game unplayably slow. Any ideas?
Answer by Eric5h5 · Feb 14, 2013 at 10:30 PM
Because you have 6X the draw calls. You can use a texture atlas instead, so you don't need to have separate game objects and materials for the individual faces.
Each face is an instance of the same prefab, just rotated 90 degrees. Even if there is no texture applied, it still runs slow. In total, there are only about 1000 GameObjects.
I don't understand. What use is a texture atlas when all of the faces share a single texture, or have no texture at all? And in any case how would a texture atlas obviate the need for separate GameObjects when I want to be able to manipulate each of the faces individually?
Sorry, I assumed by "manipulate each of the faces" you were talking about textures. If you're physically moving the faces around then you're not really using cubes. In that case you should use the $$anonymous$$esh class and change the vertices, so you can have many objects in one mesh, ins$$anonymous$$d of so many separate objects. Or you could use a skinned mesh and bind each face to a bone, and use the bones to move the faces around. That would be less performant than a normal mesh, but easier to manipulate.
Excellent. I will definitely look into that.
As someone new to Unity but not to game development, I wonder if you might indulge this question a little further and a little more fundamentally...
Is 1000 GameObjects a lot? Are there structures in Unity better suited for simple actors?
Is there a significant performance penalty for multiple generations of transform parentage? That is, does a visibly indistinguishable GameObject that is composed of children and grandchildren incur performance costs other than additional draw calls?
Is there a significant difference in performance between Transform.Translate/Rotate and assigning to Transform.position/rotation?
Thanks again.