I’ve been reading everything I can find regarding draw calls, batched draw calls, combining mesh etc… however I cant seem to find a solution or reason to my current problem. (using Unity iPhone 1.5)
I’m making a small space shooter game for the iphone and I really want to optimise performance as much as possible (duh :P). Currently I’m spawning an amount of ships on the screen, each one with independent movement and I would like to keep them at 1 draw call total.
I started out with just plane boxes with white textures, as shown in the picture below.
Which is working fine, Unity is automatically Batching them for me so I’ve only got 1 Draw Call - Great.
However when I change the model from a plane white box to my simple Spaceship Model it now uses a separate Draw Call for each object. (each model is using 1 mesh and 1 texture - the ships are direct copies of each other)
So now its no longer Batching, and using 4x as many draw calls which is want I want to reduce back to 1.
I have tried playing around with the “Combine Children” script, which works to an extent, reducing the Draw Calls to 1 when the ships are immobile .
But when I activate my Enemy Ship Script which tells them to move around I get the following result. (The script sets a rigidbody.velocity value if that means anything)
The models of the ships stay in the same spot and only their other components are moving around the screen.
objects will automatically batch if they use the same material, given they have less than 300 triangles (300 vertices once fixed in 1.5.1 from what mentioned) and are not skinned.
According to the stats window, each ship is 173tris / 272verts, and I’ve tried just giving them all the same plain white texture.
Yet the still aren’t being batched.
Is this outside the limits for automatic batching?
And how can I tell if something is skinned or not, I assumed testing with a plain white texture would eliminate that factor.
I’ve requested a copy of iPhone 1.5.1 to see if it makes any difference.
What’s important is not the texture, but the material, which must be the same on all objects in order for batching to work. If something is skinned it has a skinned mesh renderer (and says so in the stats), nothing to do with the texture.
There is no problem if they are skinned; batching still works as you can see below.
Unity iPhone 1.5.1 should be out really soon now it seems, and it will open Unity 2.6 projects. Unfortunately I can’t think of anything else that could be the problem, as batching works as expected (aside from the 300 tris/300 vertices mixup) here.
I don’t recall anyone saying that animated meshes wouldn’t batch. Although it’s possible the stats are incorrect and they actually don’t on the device, but I haven’t tested.
Anyway, I tried out the test project and it’s batching here, although I’m using 1.5.1 so I can’t say for sure if it works on 1.5.0.
The objects batch fine for me. Try zooming the Scene view camera in and out. I find that doing so is necessary in order to refresh the number of draw calls, frequently.
Hmm your right, if I maximise the game view It will batch the two ships into one draw call. However each ship I add after that adds its own draw call, strange.
In a test project, I have two SpriteManager objects that use the same Material. Each SpriteManager adds a number of sprites, although the combined vertex count is under 300.
While in the editor, if the game is run and there is a visible “Scene” view, batching seems to be disabled. For example, when I run the game using the “Tall” or “Wide” window Layouts (Window > Layouts > Tall), the Statistics overlay shows batches, yet if I instead use the “2 Split” or “4 Split” layouts, it always shows 0 batched.
Regardless of the layout I’m using, if I hit the spacebar to full-screen the “Game” view prior to pressing Play, the Statistics overlay also shows batches. This likely works because any “Scene” view would be hidden when the “Game” view goes fullscreen.
This appears to be a bug. Is there any reason for this behavior?
Since I’m developing for the iPhone, I would like to verify that the meshes are being batch when the game is running on the device. Is there a way to test for this? When I enabled profiling by setting “#define ENABLE_INTERNAL_PROFILER 1” in AppController.mm, the console report says “batched: 0” where should so say “batched: 2”.
Does batching work on the iPhone/iPod Touch? The device I’m testing on is using OS 2.2.1.
I was going to say that was because the manual says:
“Once combined gos can NOT change their Transform properties, however staticBatchRoot can be moved.”
So your meshes stayed in place, but then I set up a little test project and was able to move merged meshes individually.
I also noticed that I did not need to select “Static” to make it happen… they just merged. I’m very confused about this. Did something change in 1.5 that lets us batch movable meshes?