I was experimenting with whether I could achieve better rendering performance by using a Mesh Combine package to combine many static meshes into a single mesh. The objects I’m combing are modular pieces I use to create level geometry, in this case some simple metal platforms:
These are static objects, and I tried combining them. I looked at draw calls and vert/tri counts counts before and after, and found that combining the meshes led to worse performance in most cases. The main reason, I believe, is that Unity is probably drawing the entire combined mesh even if only a tiny portion of it is visible. In other words, I assume the performance hit is due to the lack of frustrum culling when the mesh is combined.
So I was just wondering if there are some cases where combining static meshes is generally better than keeping them separate?
World to the West was built though combining static meshes. Our levels were a 1x1x1 grid generated from a 64x64 heightmap. Each cell got assigned a mesh, and those meshes were combined together to form the level.
If we didn’t combine those meshes, the game ran really poorly, so combining them was definitely necessary. But, we ran into the same issue as you do - no part of the level geometry could ever be culled, as some part was always on the screen.
The solution was super-simple; We simply chunked the level into appropriately sized parts. I don’t remember exactly how large those parts needed to be for optimal performance, but I believe we went with something like half the width of the screen. So instead of having a 200x200 combined mesh, we had something like 16 50x50 meshes.
Figuring out the right size just took trial and error. So I suggest you build a tool where you can switch the chunk sizes relatively quickly, and then test until you find the one that gives the best performance.
Thanks for the recap. You’re probably using orders of magnitude more meshes than I am, as in the worst case I only tend to have about 50-100 meshes total combined in this way. So my guess is I won’t really notice the performance impact of this small number of static meshes either way. But it’s good to know there’s some inflection point where combining the meshes would probably start performing better than leaving them separate. I appreciate the anecdote. I expect this will become more relevant/important as I start working on levels that I build more modularly, rather than having simple ProBuilder geometry.
You should combine meshes in a way that allows them to be culled.
For example, if your level is a bunch of rooms you go through, combine meshes in each room and don’t combine across rooms, because you would want to cull meshes from another room when you don’t see any of them.
Definitely. That was already the approach I took. I figured combining everything on a per-room basis made sense. But even in that case, for a catwalk that extends across the whole room (for example), I was rendering more verts and tris when combining the meshes than when they were independent, small static meshes. That’s because the small static meshes could be frustrum culled, while the large one could not.
In any case, I think I’ll be abandoning combining for the most part, as it just doesn’t seem like I have enough small meshes in each scene to really have to worry about it at this point.
Sure, that’s the default behavior, and that’s what I’ve been doing. The question in this thread is, Under what circumstances is it better to merge multiple static meshes into one single larger static mesh than to have a bunch of static smaller static meshes. Unity does indeed appear to do a very good job of batching up many small static meshes, which is why I wasn’t clear when (if ever) it was preferable to combine static meshes. But so far, the answer seems to be that the right time to combine static meshes is when the number of meshes is very high, much higher than in my use cases.