|
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.
(comments are locked)
|
|
Adding a texture to each object makes it have its own unique material, so it can't batch. 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)
|
|
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 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)
|
|
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
(comments are locked)
|
|
Other things that break batching:
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)
|
|
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!
(comments are locked)
|
