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
0
Question by Triqy · Sep 30, 2013 at 02:34 AM · materialbatchingtextureing

Why does applying a material to a object break batching?

Why does applying a material to a object break batching?

Comment
Add comment · Show 1
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 Triqy · Sep 30, 2013 at 02:41 AM 0
Share

I mean applying material through script.( to specify )

2 Replies

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

Answer by robertbu · Sep 30, 2013 at 05:40 AM

Assigning a new material does not break batching. The object you assigned the new material will batch with other objects of that same new material. Here is a script you can run to verify. Attach it to an empty game object, drag and drop two or more materials into the materials array in the inspector, and hit run. Spacebar will advance to the next material. You should see that all the cubes are still batched even when the material is changed.

 #pragma strict
 var count = 100;
 var materials : Material[];
 private var iMat = 0;
 private var objects : GameObject[]; 
  
 function Start () 
 {
     objects = new GameObject[count];
     
     for (var i = 0; i < count; i++) {
         var go = GameObject.CreatePrimitive(PrimitiveType.Cube);
         go.transform.localScale = Vector3(0.25, 0.25, 0.25);
         go.transform.rotation = Random.rotation;
         go.transform.position = Random.insideUnitCircle * 5;
         go.renderer.material = materials[0];
         objects[i] = go;
     }
 }
  
 function Update()
 {
     if (Input.GetKeyDown(KeyCode.Space)) {
         iMat = (iMat + 1) % materials.Length;
         for (var i = 0; i < objects.Length; i++)
             objects[i].renderer.material = materials[iMat]; 
     }
 }

What breaks batching is changing some property of the a material like texture, or color, or blending, or offset, or... If you change a property of the material, Unity creates a new material instance...it is no longer the same material. The reason it breaks batching is that the shader needs all the properties to be the same in order for the game objects to batch. For example a shader cannot handle two materials where the main color attribute is different at the same time.

Comment
Add comment · 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
0

Answer by reefwirrax · Sep 30, 2013 at 07:57 AM

you cannot batch 2 objects with 2 different materials, even if it's the same one, unless you use sharedMaterial.

unity free is less good at batching, there is a script somewhere that can textureAtlas multiple textures, but it is a tedious thing to do when you're trying to focus time on a game.

Comment
Add comment · Show 1 · 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 robertbu · Sep 30, 2013 at 08:02 AM 0
Share

Not strictly true. The script above reassign a material without any reference to 'shared$$anonymous$$aterial,' and the objects continue to batch. The material is the shared material in the project since I've not made any changes at runtime, but I don't have to explicitly use 'shared$$anonymous$$aterial.'

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

15 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

Related Questions

Point lights break dynamic batching even when using Unlit 1 Answer

How to know if my Shader Graph is supported by the SRP Batcher? 1 Answer

Changing two different objects renderer colour 1 Answer

Dynamic batching not working? 0 Answers

How to make common material for CPU optimization? 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