• 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 StaticBatc$$anonymous$$ngUtility 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 batc$$anonymous$$ng.

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 batc$$anonymous$$ng, 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 batc$$anonymous$$ng.

If not, what is the best way to perform the batc$$anonymous$$ng?

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 batc$$anonymous$$ng bakes your models into one huge mesh. T$$anonymous$$s 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 somet$$anonymous$$ng, 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 t$$anonymous$$s 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 t$$anonymous$$ngs outside your frustum.

T$$anonymous$$s 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 batc$$anonymous$$ng. T$$anonymous$$s is typically what happens for static batc$$anonymous$$ng.

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

Static batc$$anonymous$$ng 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)?

My 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. Make a test. Make 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(GAMEOBJECT)), 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 StaticBatc$$anonymous$$ngUtillity.Combine() in my project. with t$$anonymous$$s you can batch several models under virtual one model.(well not really virtual since you can see it in the $$anonymous$$erarchy when the project run). by t$$anonymous$$s 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Should I build my level with few meshes or many meshes on the iPhone? 1 Answer

Batching problem: Poor forest tiles don't batch [fixed but not sure why xD] 1 Answer

Are batching and atlas almost useless ?!!! 2 Answers

Vertex colours - can they improve performance? Do they affect batching? 1 Answer

[Closed] Manually Batching GUI Texture Objects? 0 Answers


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