questions about static batching

I have a question about static batching. Is there a difference between me combining models in a 3d package as much as i can per location vs using static batching to statically batch everything…

The question is in performance difference i guess.

Guess im just wondering if theres some sort of overhead in letting 1000 things get static batched through unity vs combining stuff myself and using static batching less where maybe 20 things get static batched.

Yes, static batching still works with frustum culling and occlusion culling properly, making a BigHugeMegaMesh does not. The only drawback with static batching is that it makes for larger builds.

–Eric

I don’t mean 1 huge mega mesh… I mean combining based on what u would see … stuff in a room gets combined in the 3d package… piles of trash in a back alley combined in 3d package in 1 spot rather then in unity. That was occlusion still works to a point. I guess its like a pile of 50 trash bags. (just an example) better to have 50 trashbags in a pile be statically batched in unitys side or just combined into 1 big mesh since there all in the same area anyway?

I guess im just curious if theres some sort of performance hit on the cpu or gpu side that happens when unity static batches stuff in a scene. Even if it means more memory gets sucked up somehow.

Heres a better example.
Scene 1 is 1 big combined mesh in a 3d package and brought into unity.

Scene 2 is 50 smaller meshes statically combined .

Both scenes have 1 draw call … 1 material… Same amount of polys on the screen at once for both scenes as well.etc.

Is there a difference performance wise? Is there a difference memory wise?

Anyone got an answer to this?

Are your 50 smaller meshes all separate game objects? In that case, your one large mesh would probably be better to a point. Have you just tried it to see what the performance difference is?

I have not because with testing out a bunch of cubes your probably not going to see a performance difference. But if you build your artwork out of this mentality that its better to combine and work LODs out of that vs prefabs of the same model all over the place. In theory the draw calls would be the same, but just looking to find out if there is some sort of overhead that could hurt you from static batching. Because it seems like there would need to be some sort of calculation going on with all these pieces… or if static batching works by making combined variations behind the scenes… (ive heard that somewhere but don’t know if that’s true… which would make a ton less memory available to you with the static batching approach… so I have no idea.)

Ok, so I believe that Static batching happens at build time while Dynamic batching happens at load time. This is why static batching is a pro feature… it reduces load times by allowing the batching to be calculated up front and not having to be done by the game engine… so to answer your question about the batching process itself, it should not affect your performance.

I think your a little confused. Dynamic isn’t of use in this situation because it batches stuff in realtime that are really really low in polygon count. Dynamic batching wont batch big props or decorations. (unless of course your saying batching stuff together on load time with a script).

Static batching itself does get calculated up front, but then again that raises a number of questions. A.) How does it detect whats visible and whats not, wouldn’t that take some processor power? How does combine the objects? Does it create instances in the background that get loaded into memory of different view based circumstances? In sense creating models that are combined in different scenarios? Then obviously again is the question does it add additional memory because of that… would it be better to combine things in your 3d package first.

I notice things like on the bootcamp demo how they used a script to combine all objects at load time depending on location and depending on material. Why would they do that if static batching alone was so effective?

Then another question is actually do LODs get the static batching treatment. Will LOD2 objects get batched with LOD1 objects if they share the same material?

Then that even another question… LODs… does it take performance to calculare the distances from you to the object for LOD? In that case is it better to create an LOD as 1 object in the room with its LODs or 20 different Objects that have LODs that need distance calculated…

It goes to wether more separated objects is fine and more convenient to just do static batching or do u put the work in and have less individual objects… if that is the better way to approach it.

Because static batching is Pro-only (it might also have been created before static batching was a thing). If you want performance info, do a test where you have static batching active vs. not active, and see what the difference is.

–Eric

That is often the case. :slight_smile: Recommended reading:

http://docs.unity3d.com/Documentation/Manual/DrawCallBatching.html

OK I did the test. And rather disheartening but static batching is not as good as combining by hand. This is an extreme test… and A HUGE DIFFERENCE in performance. This is on my laptop which is a core 2 duo with an NVidia 9700 gts

As you can see combining in maya draw calls were at 15 while unitys static batching was at 49. Why? I have no idea… doesn’t make much sense.

Maya draw calls frame rate is maxed out, while unitys static batching the fps dropped down to 9!

Polycount for both tests was exactly the same.

Even worse unitys static batching used up about 20 more mb… at least that’s what it looks like.

The main thread and render was about 10x higher in the unity static batching test.

My personal opinion after this is to use static batching or any batching as sparingly as possible… and combine all objects in the same room and count on batching if you happen to see 2 rooms at once or something.

First screenshot of it combined in sections in maya

This second screenshot is with relying on unitys STATIC batching

1 Like

You could try out Mesh Baker to keep flexibility (moving objects around and such). It combines objects for you and atlases them and hides the original meshes.