I have over 160 GameObject which each contain a meshFilter and a sharedMesh with 4 vertices. They all have the same material.
So when I put then on the camera, the whole thing is batched automaticly (thanks to Unity3 !). But if I try
var meshF:MeshFilter = GetComponent(MeshFilter);
Graphics.DrawMesh(meshF.sharedMesh, pos, Quaternion.identity, meshF.renderer.sharedMaterial, 0);
I can see the visual properly, but they are not batched anymore. Anybody have an idea ?
What I’m trying to achieve is store and load about ~500 prefab once, and draw them on the screen myself, calculating their positions etc (for a 2d iphone game).
batching will not work with manual draw commands. they explicitely create own meshes.
May I ask why you don’t create these meshes programmatically through the mesh class, hook them up on GOs and use them like that in which case they would batch?
Alternatively you can naturally also do the batching on your end and draw 1 mesh per material with all the corresponding vertices and triangles in.
But seriously, I’ll explain my problem in more detail.
To put it simple, I’m working on the port of this game http://www.berzerkstudio.com/games.php?game=4 I have about 400+ textures of different non-unifrom format. I used Sprite Manager 2 and I think that’s what the script does already.
When I put my game on my iPod touch, according to the iphone profiler, the main thing that is dropping my FPS down is my scripts. So I wanted to optimize them and not create / cache GOs each frame, hence the solution I thought about above.
But maybe I don’t understand your solution perfectly ?
I have only one main script that is updated and create all my GameObject (Prefab with PackedSprite attached), and according to Unity profiler, that’s the main script who takes all the cpu power.
Ah, well, in that case Graphics.DrawMesh probably won’t gain you anything in this case, except saving some memory, at the expense of not having dynamic batching. Sounds like you should try to optimize the script in other ways.