- Home /
How to tell if static batching is working?
Hi,
I have a large, open landscape scene with lots of rocks (maybe 100 or so). The rocks all share one of six different materials. According to the doc on static batching, Unity - Draw Call Batching, if I check the Static check box these rocks should batch. However, when I run the scene, the stats always show zero draw calls saved by batching. Is static batching in fact happening? If not, how can I make it happen? Thanks.
Zaffer
No, I don't believe it is happening. It must be something else. Are these rocks you are creating from a script or have set up the scene ahead of time? Are you changing any textures during runtime or doing anything during runtime to them?
Also, check the scaling of the rocks. AFAI$$anonymous$$, the objects scaled on different axis do not batch. e.g. the rocks scaled like (1,1,2) and (1,2,1) won't batch, but (1,1,2) and (1,1,3) will be. If you are setting the scale factors on runtime i.e. through scripting, you should take care of this.
also, can you post a screenshot of the scene with the hierarcy in the screenshot as well.
I modeled the rocks in Blender, making them in 3 different shapes. I then made prefabs for each of the shapes in 7 different sizes with 6 materials for each (see screen shot) – plus some miscellaneous larger rocks for a cave. I’m not changing the textures or doing anything to the rocks at runtime. As for scaling, all the rocks are scaled at 1,1,1 at all times (that’s why I made so many different sizes, to avoid scaling). Thanks for your help, I really appreciate it.
It's no problem. I checked out your scene on your website and it's nice.
Did you make 6 materials for each size or each of those many rocks?
anyway, i think it's solved now. You should just make a prefab for each unique rock mesh, (not each size of each unique mesh UNLESS you want it to look really different (like really tall or something..but that will mean it can't be batched, and is often better solved by just creating a new unique mesh). You should be able to scale (in all directions equally) for each rock later when you place it in your scene. If you drag one prefab into the scene, then duplicate it (Ctrl-D) and resize it (equally), it takes no time, and you can have a wider variety of sizes, plus it will batch. Then apply one of your 6 rock materials to it..(you should only have 6 rock materials total, not 6 for each mesh (if they are seamless textures)).
if you have 6 materials for each of the 3 unique rocks, and use all 18 rocks in the scene (and they are visible), it's at least 18 draw calls and 18 objects. (assu$$anonymous$$g no bump or specular maps or anything else on your material). But even so, you can duplicate these rocks and resize as many times as you want and it should still batch.
Now on the other hand, if you have only 6 unique textures total, and 3 unique rocks, then use the 18 combinations, you shouldn't get any batching, but your drawcalls should be just 6.
IF you have a unique material for each rock AND size, batching won't help a lot :).. aka, if you find two materials with the same texture, and nothing else unique about them, delete one.
As a note: the scene will only inform you of objects and batching when it sees to of the same rock in the viewport. If you have one rock on the other side of the board that is the same as a rock you are viewing, it won't batch, because it won't even be drawing the other (far away) rock. (not drawing something in the first place is of course, better than batching) :)
Try a new scene, drag in a rock, and then duplicate it in the scene. (You may want to test scaling, but i'm almost positive equal scaling will not affect batching. )
SO basically, to batch, the object must have the same $$anonymous$$aterial, and scaled equally in all directions only (or not scaled at all)
anyway, if that doesn't work, post back as something really strange is going on. (= but i doubt it.
Your answer
Follow this Question
Related Questions
Getting statistics info in a script? 0 Answers
Static batching doesn't reduce draw call 0 Answers
StaticBatchingUtility.Combine crash on device 1 Answer
Texture Atlasing only beneficial with Batching? 0 Answers
Static batching not working 0 Answers