Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by laurG · Sep 19, 2017 at 12:06 PM · performancedraw calls

Single Mesh vs Batching - Performance

Hello!

Does combining scene objects (that use the same material) into a single mesh is cheaper than relying on Unity's batching system (performance wise)?

So scenario is: 1 mesh - 1 material vs multiple meshes - 1 material

At first look I'd say it is, but I'm not sure, that's why I decided to ask.

Thank you!

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

1 Reply

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

Answer by Bunny83 · Sep 19, 2017 at 12:52 PM

In general there are two different batching systems in Unity:

  • static batching

  • dynamic batching

Static batching essentially is the same as combining the objects manually. This is only viable for objects that do not move. Unity automatically performs static batching when loading a scene that contains objects which are marked as static for batching. Once batched you can no longer move the objects as they are now part of a larger mesh.

For procedural generated levels you can use the StaticBatchingUtility to manually batch objects together at runtime.

Dynamic batching is different. It only applies to objects that meet several criteria:

  • Only small meshes are supported. That means the mesh can't have more than 900 vertex attributes. A single attribute is for example the vertex position. Others are a vertex normal, uv coordinates, color, tangent, ... So if your mesh vertices define a position, a normal and texture coordinates the mesh can only have 300 vertices. If the mesh has more attributes per vertex the number gets even smaller.

  • The objects shouldn't use different scaling or they might not be batched.

  • Objects are not being batched if you use lightmapping and the objects are located on different lightmaps.

  • The objects can't use multi-pass shaders as they generally don't batch.

  • The objects need to be "close together".

Dynamic batching is done each frame and has some performance overhead on the CPU. It's ment to batch several small objects (like many flying bullets).

The most efficient batching is static batching. It has some memory overhead due to the combined mesh instance. Dynamic batching is only useful in special cases. It's nice to have but it's difficult to rely on dynamic batching without fine tuning the objects you want to batch together.

Static batching works great. It probably has a larger memory overhead over manually creating a single mesh, but it saves you from manually combining meshes. It allows easy modular level design and good performance at runtime out of the box.

Comment
Add comment · Show 4 · 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 laurG · Sep 19, 2017 at 01:51 PM 0
Share

Well my level is procedurally generated and also moves (for an endless runner on mobile game, player does not move on the Z axis, but the enviroment does).

I already created an editor tool that allows me to quickly Combine meshes that use the same material together. (For example I select a whole environment section and apply the tool on it, the result will be 1 $$anonymous$$esh with however many materials there are submeshes).

Also, most of the props share the same material that uses only vertex colors (unlit), so this works great, I get ~95% less draw calls.

What I was wondering is if it was redundant, in case Batching would do this automatically for me.

From your answer I take that it's safer the way I do it. Even if I scale objects or move them are runtime, they will be combined together in a mesh so I won't have to worry about whether they are being batched or not.

Is my assessment correct?

Thank you!

avatar image Bunny83 laurG · Sep 19, 2017 at 02:15 PM 0
Share

Well, using the StaticBachingUtility would still allow you to move the parent object, but not individual objects after they are combined. So if you have for example several "sections" you can statically batch each section individually so each section is optimised on it's own.

There's one advantage of using static batching over manually creating a single $$anonymous$$esh. Statically batched objects are still culled individually even they are rendered as a single mesh.

avatar image laurG Bunny83 · Sep 19, 2017 at 02:39 PM 0
Share

That is very interesting. Didn't know about the culling part of this. I wanted to optimize the overdraw, but was unsure how to if I was going to combine meshes.

I will try this and get back to you.

Thanks!

Show more comments

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

86 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 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 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 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 avatar image avatar image

Related Questions

dynamic batching problem with spriterenderer 1 Answer

Does Graphics.Blit affect performance much when used in image effects? 1 Answer

How come setting sprite tint/alpha does not increase draw calls? 0 Answers

Bizarre Terrain-Drawcalls inconsistency? 0 Answers

What kind of performance impact does looping anmiations have on a game? 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