x


Dynamic batching

I'm trying to incorporate dynamic batching into my application. As I understand it, Unity should be automatically batching objects with the same materials. I have a prefab in my Resources folder that is cloned multiple times in the scene and its own texture added to it (one of three). The mesh is a low-poly object, so I know I'm under the limit for batching objects. If I pause the game and look in the editor, the material of the all of the cloned objects become "rocket-01-default (Instance) (Material)". My question is what do I need to do to get these objects to batch? Do they not batch because the material has (Instance) in it after it clones? If so, how do I change this?

Thanks.

more ▼

asked Jul 16 '10 at 06:35 AM

kieblera5 gravatar image

kieblera5
51 1 1 3

(comments are locked)
10|3000 characters needed characters left

5 answers: sort voted first

Adding a texture to each object makes it have its own unique material, so it can't batch.

more ▼

answered Jul 16 '10 at 07:34 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

I have three different textures and only one material, so there are three combinations. There are up to 10 bullets on the screen at once, so there would have to be duplicates, but these do not batch even though they have the same texture and material. Why is this?

Jul 16 '10 at 07:45 AM kieblera5

@kieblera5: you cannot have one material when you assign different textures to the objects. That automatically makes them unique materials.

Jul 16 '10 at 07:49 AM Eric5h5

One more follow-up question. I just remade my entire setup. There are now three separate prefabs. Each prefab has its own material and accompanying texture set inside the prefab. The material and texture are no longer being set or altered in the code; however, two objects of the same material/texture are not batching. Did I miss something that you said or am I doing something else wrong?

Jul 16 '10 at 08:29 AM kieblera5

@kieblera5: the objects must have fewer than 300 vertices each.

Jul 16 '10 at 09:36 AM Eric5h5
(comments are locked)
10|3000 characters needed characters left

How to Make Objects Dynamically Batch in Unity

they must share the same material

the material must not be instanced (check material name in debug inspector)

batching is applied only to meshes containing less than approx 900 vertex attributes in total (check mesh properties for some idea about this; for starters turn off normals & tangents to reduce it)

the textures must not include alpha

scale breaks batching

lightmaps break batching

multipass shaders break batching

layering other objects in between objects trying to batch can break batching

if you are instantiating the object in code, you may be instancing the material; try re-applying the material asset through .sharedMaterial

even within single-pass shaders, some can batch higher vertex attribute counts than others... in particular if you use a shader that colors vertices you’ll be adding attributes

more ▼

answered Sep 20 '12 at 03:31 PM

nerophon gravatar image

nerophon
31 2

is there any reference for these things you can point us to, or have you experienced these things for yourself? How do you find out if a specific object is dynamically batched or not?

Jan 18 at 08:51 AM VivienS

and what does "layering other objects in between objects trying to batch can break batching" mean exactly? how can you layer an object in between objects?

Jan 18 at 09:00 AM VivienS

these points were learned through experience; the Unity docs are far from comprehensive on the subject. As for layering, I mean it literally: if you have a mesh spatially overlapping mesh objects you are hoping to batch, that batch may fail; simply move the intruding object out of the way (in world space) and watch your dynamic batch count rise :)

Mar 19 at 01:12 PM nerophon
(comments are locked)
10|3000 characters needed characters left

Even so, <300 vertices and one single material for all, they won't batch if scaled in the editor, Also it seems that Cloned objects with correct settings won't batch either. When you Instantiate a clone, it will be carried out as myobject(clone) and its material as thematerial(clone) this will result in not banching the object, and this is though to spot, as these objects are generated at runtime, so..

Try to put your batching materials into the resource folder, so that you can apply later the correct material, this should do the trick

more ▼

answered Dec 02 '11 at 12:34 AM

LitobyteSoftworks_answers gravatar image

LitobyteSoftworks_answers
16 1

(comments are locked)
10|3000 characters needed characters left

Other things that break batching:

  • Turning on Mesh Compression! No idea why.
  • Using a shader that alters a vertex position / colour / UV, as this automatically creates an instance of the material.
more ▼

answered Mar 19 at 12:57 PM

Madrayken gravatar image

Madrayken
1 1

Thank u, my models had mesh compression and i didn't know why it didn't batched, and i was very nervous cuz i triyed ething!

7 days ago moregergely0001
(comments are locked)
10|3000 characters needed characters left

There appears to be a huge list of 'what breaks batching'. Is there any way to definitely examine an object, and unity say "This object cannot be batched due to alpha textures" (or whatever) ?

It seems far too easy for your artist to accidentally break batching by making an object 301 polys, or including 1 pixel of alpha, and no-one will have the slightest clue why the framerate suddenly plummeted!

more ▼

answered Nov 29 '12 at 04:58 AM

djarcas gravatar image

djarcas
1 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1999
x472
x274
x115

asked: Jul 16 '10 at 06:35 AM

Seen: 7325 times

Last Updated: 7 days ago