I am black box profiling draw calls on someone else's iOS unity game. How do I count what is incurring draw calls?

I am profiling a friend's Unity game and it is running at about 300 draw calls on iOS. It is good to know this is the time spend culprit, but I need some method or technique of identifying what in his complex code is actually incurring the draw calls.

Questions I would like to be able to answer:

  • For each mesh, how many draw calls per frame?
  • How many discreet materials in the scene? (essentially failing the dynamic draw call test)
  • Is there some way of debug visualizing draw calls? (ex: draw a point at the camera-transformed median point of each draw call)

Currently the draw call system is a big black box and it appears that I need intrinsic knowledge of the game's implementation to start making fixes. Are there profiling tools that simplify this?

I am using Unity Pro iOS

For each mesh, how many draw calls per frame? I usually brute force this by adding that 1 object into a scene and seeing how many draw calls it uses by opening the stats window. Then i slowly make copies of that object or other objects and verify that batching is occurring as expected. It's slow but it works.

How many discreet materials in the scene? (essentially failing the dynamic draw call test) you can write an editor script to log this information to the console. The editor scripting is pretty amazing once you get the hang of it. Write a script to get the current selection in the editor and recurse through it finding all of the renderers. Get the names of the materials used and do some processing on that.

as a side note, I did a LOT of testing last night and found this to be true. Currently in my app, (dunno if it is the same for you..you should test by placing quads in an empty scene and watching the draw calls as you duplicate the object over and over) the limit for a batch of objects is around 512 verts. Anything over 512 verts TOTAL in a batch will result in a new batch. I think the best approach is to organize objects based on vert count and frequency in any one scene. If a set of objects are going to break the 512 vert limit in any one view then take that model out of that material and place it in another one. Put objects together that are not likely to exceed 512 verts in any one view.

Dunno bout the other one.

Check out this official Unity page about performance tuning for iOS: http://unity3d.com/support/documentation/Manual/iphone-performance.html

There is also a nice article in Unity Creative Jan/Feb 2011