- Home /
Why do prefabs have redundant transforms?
If I import a mesh (OBJ, FBX, whatever), it gets created as a GameObject with a Mesh Renderer, Transform, etc etc. Now, if I create a prefab from that mesh, by default the prefab consists of a 2-object hierarchy. The root transform, and the mesh as the only child. Both of these objects contain transforms, and presumably I can use the child transform to tweak any scale/rotation issues that might come from the source asset.
However, if all the assets are correct to begin with, and that child transform stays an identity matrix forever, I feel like doubling all the transforms in the scene is a bit of a waste. Is this something to concerned about? Matrix math is not a terribly expensive operation, but what about as scenes get larger? I'm working on a grid-based game, and if a level is a 20x20 grid, that's 400 redundant transforms right there, and that's just the ground tiles. Add in another batch of detail objects for the level, and that number gets larger and larger.
As an alternative, I can tweak the prefab a bit to get rid of the empty parent transform, and just have the mesh as the top-level object. In the image clipped from my hierarchy, I have a crate mesh with an empty parent (the default Unity behavior), vs the crate as its own GameObject. Is there something wrong with going this route, something I might encounter later on that could be disastrous? Or does Unity somehow ignore the redundancy (or it's so trivial a cost I shouldn't worry)?
The thing is, you don't create 400 prefabs for a 20x20 grid. You create a two-dimensional array ins$$anonymous$$d of create the mesh procedurally as one (or maybe as multiple chunks, but not with one gameobjecct per grid position).
Back to your original problem: Normally, imported meshes that you drag into the scene and then drag into the project window to create a prefab stay one GameObject, not two. Only skinned models have a hierarchy. I did what you did and just get rid of the parent transform to keep it all flat, it doesn't matter and you are free to do it.
Thanks for the clarification. Not sure why the meshes are imported the way that they are, but I've started to modify them to only have the single transform in their prefabs.
Your answer
Follow this Question
Related Questions
how to replace multiple game objects with different transform component with same prefab? 1 Answer
Script is reading from prefab instead of instance 1 Answer
Prefab mode doesn't show prefab, still shows old scene. 7 Answers
Creating a weapon database from prefabs 1 Answer
Cant delete clones of prefab 1 Answer