- Home /
Batching runtime instanced Objects
Hi guys,
Can some one guide me on the code how to batch game objects which are instantiated at runtime.?
I'm having a model which I'm keeping as prefab. I'm instantiating this object at runtime say 1 instance per minute (all are having same shared material).But the game-object wont batch (they are having more vertices) even if keep duplicates in the scene without runtime instancing.How can I do this so that it will give me only draw-call.
You are making no changes to the material at runtime? Your models have less than 900 vertex attributes? Is it in any way material dependent? That is what happens if you use a very simple material such as Unlit/Texture?
No i'm not making any changes to the material at runtime. Base vertex count is 288 (attributes - transform,normal,UVs) so 288 x 3 = 864. $$anonymous$$y materials is just a 'Diffuse'
They should be batching. Replace your mesh with something simple just as a test. An attribute count of 864 is close to the 900 limit.
Replacing that with simple mesh(less vertex count,sphere,cube,cone) works fine,its batching. But this is the specific model I want to batch.its a race track I made.I tried another track piece (B) its showing 198 verteics in modeling software and in unity if I debug.Log(GetComponent().mesh.vertexCount), its showing 378 still not batching.
Another track piece (C) shows 198 in modling sowftare and in unity vertexcount its 224 and batches fine.
Check to see if UV1 is getting set by your authoring tools. Note $$anonymous$$esh.vertexCount returns the number of vertices in the mesh, not the number of vertex attributes. You have to multiple this by what you are using: position, normal, UV0, UV1 to get the total number of vertex attributes.