Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by ZaidesA · Dec 09, 2013 at 06:34 PM · batching

How static batching works

Hi everyone,

I need to use the StaticBatchingUtility to batch all the static GameObjects in my scene. The GameObjects have to be dynamic at start (so I could access and change meshes), so I can't use unity's default batching.

The problem is that my scene is pretty big, and I have lots of GameObjects scattered around the scene. I can't just batch all the Objects with the same material to one mesh, because they might be far from each other and it is not effective.

As far as I understand, when unity does the static batching, the objects are batched in groups, and not in one big mesh. An I correct? If it's the case, is there a way to see those groups? So I will be able to save them and than use them in my own batching.

If not, what is the best way to perform the batching?

Many thanks, Anton

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
16
Best Answer

Answer by Statement · Dec 09, 2013 at 06:58 PM

Static batching bakes your models into one huge mesh. This means that if you had 1000 wall segments, all using the same model, then static batched them, you'd be using 1000x memory than using a single model. It would reduce draw calls on the expense of used memory. Put simply: It creates one huge mesh out of several instances of smaller meshes.

When you render something, a few pieces of information is required, like what model to render, what indices of that model should be rendered and what material to use.

Unity will try to render as many parts of your staticly batched mesh as possible, using a shared material. If there is no shared material, and if many parts use different materials, Unity is forced to render each collection (based on material) individually.

Even if it's one big mesh that is generated, not all of this is used to render it every frame. Unity will look at what renderers should be visible, and rebuilds an index buffer for your statically merged mesh. Put simply: Unity will exclude the vertices that belong to a renderer that is not visible when rendering the mesh, to avoid rendering things outside your frustum.

This process has some overhead of course since Unity has to rebuild indices every time a renderers leaves or enters the frustum. If you are using profilers you may see that it's using some time for batching. This is typically what happens for static batching.

Batching should be used with consideration. If you are already running dangerously low on memory, turning static batching on may crash your app. Try to use few unique materials for batching as it allows Unity to reduce the number of draw calls. If batching is slow, consider reducing the number of triangles per mesh or number of renderers in your scene.

Static batching generally dramatically improves render time but may increase memory footprint.

You can see the static mesh if you have a static object and select its mesh. You can also find the mesh by going to the new Memory Profilers detailed view, or you can find it via Resources.FindObjectOfTypeAll.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ZaidesA · Dec 09, 2013 at 08:28 PM 0
Share

Thank you for the answer!

I am still a little bit confused. I understood how static batching works, but you were talking about the 'default' unity batching, right (the one that happens when an object is marked as 'static' at the start of the game)?

$$anonymous$$y problem is using the StaticBatchingUtillity.Combine() method. my goal is to achieve a batching that is closest to the batching the unity would've performed if the objects were static at start (they will be static when I perform the batching).

How can I achieve than?

Thanks again

avatar image Statement · Dec 09, 2013 at 09:17 PM 0
Share

It's more or less the same thing as what you call "default batching". Static batching is nothing more than taking a bunch of objects vertices and merging them into one huge mesh. Individual parts of the mesh can be rendered by specifying a different index buffer (which Unity takes care of, you have no control over that). So it should to my best knowledge work just the same.

avatar image ZaidesA · Dec 09, 2013 at 09:27 PM 0
Share

Please tell me if I understood you correctly: I should just apply the Combine function on all the meshes with the same material? And than a big mesh will be created, but only the necessary parts of it will be drawn, right?

avatar image Statement · Dec 09, 2013 at 10:14 PM 0
Share

I don't know, but hey here's an idea. $$anonymous$$ake a test. $$anonymous$$ake a scene that contains a bunch of objects with one material. Call Combine. Check the # draw calls in Statistics Window. Now make a new scene and have a bunch of objects with different materials and call Combine. Check the # draw calls and ensure they are not too high (should be growing linearly with the number of unique materials you use).

Be a good Samaritan and come back with a comment of your findings, please :)

avatar image abelegu2 · May 23, 2015 at 10:32 AM 0
Share

So I know this post is really old but I did just that - created a new scene with a bunch of objects using the same material.

Running the game just like that (no batching or anything, just running the game when the objects are all in view of the camera), I got these stats:

alt text

After applying Unity's default Static Batch (enabling the Static checkbox in their Inspector view), I got these stats:

alt text

Funny thing was there was no difference when doing the dynamic Static Batching (using StaticBatchingUtility.Combine(GA$$anonymous$$EOBJECT)), there was no difference from the other one, they were exactly identical.

with-batch.png (12.3 kB)
with-batch.png (12.3 kB)
avatar image
0

Answer by haim96 · Dec 09, 2013 at 09:02 PM

i'm using StaticBatchingUtillity.Combine() in my project. with this you can batch several models under virtual one model.(well not really virtual since you can see it in the hierarchy when the project run). by this you should get less drawcall when drawing the batched object. keep in mind that static object that you combine cannot be moved in scene.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ZaidesA · Dec 09, 2013 at 09:14 PM 0
Share

How do you use it? Can you give me some examples? I have a scene full of objects (trees, stones, bushes etc) scattered around. How should I approach it?

avatar image haim96 · Dec 09, 2013 at 09:41 PM 0
Share

I'm answering from my phone so if you want code sample you have to wait or search on the web. But the idea is to create an array of your game object that you want to batch and then use it with the combine method. In my case I have random level made cubes and they are static. So I when I create them I put them in array and batch them. I can tell it reduced the amount of draw calls.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What, exactly, in a shader, stops batching from happening? 2 Answers

Dynamic Batching not Batching everything 0 Answers

StaticBatchingUtility combine meshes in runtime 1 Answer

Do Dynamic Batching before Light pass. 0 Answers

Stop batching at runtime? Still in memory? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges