- Home /
Does having a large number of identical meshes hurt performance?
Say I'm building a level, and I decide to repeatedly copy/paste a particular piece of level geometry over and over again to make it easier on myself. Would this have a negative effect on the computer's performance? The reason I ask is because TheNewBoston, a popular programming tutorial maker, claims that these things called "Static Meshes" can be re-used again and again and again without too much extra work for the graphics card. The specific video that he says this in is: http://youtu.be/ueM9K-hutAE?t=5m35s (skip to about 5:35)
What I want to know is: does Unity have something that is equivalent to UDK's "Static Meshes"? Or are Unity's meshes already technically "static" by default? If such a thing does not exist in Unity, then is there some kind of add-on for Unity that adds it? Thanks in advance!
Answer by nsxdavid · Mar 10, 2013 at 03:41 AM
You are probably referring to the concept of batching draw calls. Unity can do this in a couple ways:
See: http://docs.unity3d.com/Documentation/Manual/DrawCallBatching.html
In the case of static objects, this would be Static Batching. It is not on by default, but you just need to click the Static checkbox in the inspector.
Answer by Statement · Mar 10, 2013 at 04:02 AM
For the simple case: Does copying a mesh incur significant memory overhead?
No. Go ahead and make copies of your mesh. It will most likely reuse your mesh. But keep reading for the exceptions:
However, if you have static batching enabled and if your meshes are static, then it means that the vertex data will be baked together to a single mesh. This means that it will use more memory, but it does this to render faster. It is not a good idea to make everything staticly batched since this could completely blow away your free RAM.
Another however; if you make copies of your mesh and they are not static, everything is nice and fine until you set a non-uniform scale on some of the objects. That is, if you have a tree model and make a forest of trees, you might want to make them look a little bit different so you rotate them a little and scale them a little and that's fine, but if you scale them non-uniformly for example to (2, 2, 2.4), then Unity will generate a new mesh for performance reasons. This has to do with normals on the models, where non uniform scales mess with normals. It would be possible to handle this in a shader but that shader would become complex and slow and instead another Mesh is used, trading memory for runtime performance. Uniformly scaled meshes are no problem since we can just update a shader property with the uniform scale.
To put it simple: Scale 1, 1, 1 is fine. 2, 2, 2 is fine. 3.57, 3.57, 3.57 is fine. 1, 2, 3 is not (well it's fine, but you should keep in mind that the mesh will be duplicated in memory).
And @nsxdavid has a link to the docs that explain static and dynamic batching. On second thought perhaps you only needed a link to how draw call batching is done :) But oh well, the more information the merrier.
Your answer
Follow this Question
Related Questions
Re-meshing Static Objects as one mesh? 1 Answer
Occlusion Culling with Static Mesh Render Object 0 Answers
Why isn't my static batching working? 1 Answer
Materials disappear on Mobile when more then one is set to static batching. 0 Answers
Can I not use static objects with the Local Nav Mesh Builder? 0 Answers