What performance to expect?

If I make a scene with a sphere that has a large texture material, performance is great. If I have a flat colored sphere and make a 100 planes with a solid color diffuse material at runtime, performance is very poor. Why would the demands of perhaps 200 polygons be enough to drag down the whole phone? Here’s the script I use to create the 100 planes (prefab is hooked up to a simple plane asset) :

var prefab : GameObject;
var rad : float;
function Start () {
var d : GameObject;
for (var i=0;i<100;i++) {
d = Instantiate (prefab, Vector3.zero, Random.rotation);
d.transform.parent = transform;
d.transform.Translate(0,rad,0);
}
}

If you take a look at any of the other posts about performance, draw calls is a huge issue. Above about 30 draw calls performance starts to plunge. Every high-performance game is using some trick to reduce this. Either combining objects using SpriteManager, or combining objects into a single skinned mesh.

Also, if you are talking about instancing the default plane created by Unity (in the GameObject/Create Other menu), that object has 200 triangles in it.

I made the plane in Cheetah, and I think it has very few polygons.

I’m looking around at the various mesh help pages, and haven’t yet found example code that copies and pastes and works. Some refer to using vertices and triangles, without showing how those were made, and one shows making those and supposedly using them, but it gives errors when I try it in v2.5.

Is there a small code example in the help that I’m missing, that works with v2.5?

Poly count is much less critical than draw calls. With you instantiating 100 objects, you are going to suffer a huge performance hit. Provided these objects won’t be moving, what you could do to help this is run the combine children script on the transform parent after all the instances have been created. If they are required to move, I believe there is a new script floating around that combines meshes and creates bones for you to animate individual objects.

Correction to what I said earlier, I have found mesh code that works in v2.5, it’s in Unity iPhone that the code doesn’t work. It says that mesh is not a member of UnityEngine.Component.

We must admit this draw call relative performance system is silly by the way :roll:

Why don’t OpenGL or Xcode directly optimize the scene and let the coders systematically do it by themselves ?

I don’t get it.

I think you’re reinventing the wheel here. SpriteManager and MeshMerger scripts have already been written that do what you would want: Combine a bunch of objects into a single mesh to help performance. Check out the topics on those scripts.

The error you’re running into sounds like it’s because Unity iPhone Javascripting requires strict typing, which is another subject that’s been discussed a bunch around here.

Thanks for the script typing clue. Maybe the Unity help should be updated for that?

Ideally I just want to make the whole mesh with code, and not do cloning then merging, so if I can work that out I won’t need MeshMerger.