# Calc tris and verts pr. frame in webplayer

 0 Hi there, I have some people who says parts of a level is slowing the FPS down. As the users can build the levels themselfs, I would like to examine the FPS and verts/tris in certain areas/levels.I have a FPS running now, but how do I calculate the verts/tris run-time in a scene?I cant find anything in script reference, so I guess its gotta be manually somehow. Is it "for each child gameobject in scene, calc verts/tris and check every child within too recursively" ?if so, where do I find the verts and tris? more ▼ asked Sep 18 '11 at 09:03 PM BerggreenDK 2.4k ● 54 ● 62 ● 75 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 The Mesh-class has all you need. Every mesh is made up of vertices and triangles. With Mesh.vertexCount you can get the vertex count of this Mesh. The triangle count can only be queried by reading the length of the Mesh.triangles array and divide it by 3.To get the overall vertex / triangle count in the scene just use this: ``````// C#: int vertices = 0; int tris = 0; MeshFilter[] allMeshFilters = (MeshFilter[])FindObjectsOfType(typeof(MeshFilter)); SkinnedMeshRenderer[] allSkinnedMeshes = (SkinnedMeshRenderer[])FindObjectsOfType(typeof(SkinnedMeshRenderer)); foreach(MeshFilter MF in allMeshFilters) { vertices += MF.sharedMesh.vertexCount; tris += MF.sharedMesh.triangles.Length / 3; } foreach(SkinnedMeshRenderer SMR in allSkinnedMeshes) { vertices += SMR.sharedMesh.vertexCount; tris += SMR.sharedMesh.triangles.Length / 3; } Debug.Log("Vertex count: " + vertices + " triangle count:" + tris); `````` more ▼ answered Sep 18 '11 at 10:09 PM Bunny83 45.5k ● 11 ● 49 ● 207 awesome! I found another script that did some calculations too, but it doesnt count all my dualsided alpha leafs I think or something else, because the editor shows one thing and the counter another... strange! Will try this one now. Thanks! Sep 18 '11 at 10:19 PM BerggreenDK still get different stats from the view inside the editor and then this script. any clues to why? Sep 18 '11 at 10:27 PM BerggreenDK Well, the statistics in the editor are the true vertices and tris that are send to the graphics-device. Frustum-culling and occlusion culling will reduce the vert / tris count. On the other hand there are some things you almost can't track: the GUI!Every GUI element have at least one drawcall, a button usually have two, one for the background-image and one for the text / image.There are even other things that causes draw-calls like particles, cloth, GUITextures...I'm not sure what you want to achieve? The vertex or tris count doesn't say anything about performance. Draw calls are the real problem. If Unity can batch a lot stuff into just a few drawcalls you can have millions of vertices. Also very important is what shaders you're using. If you have a bad combination of transparent shaders you will have a high fillrate (due to many overdraws) Sep 19 '11 at 02:02 AM Bunny83 drawcalls? batch... oh crap! I have around 500 drawcalls because our world is build up of small instatiated objects that grouped with a section parent. Sep 19 '11 at 07:57 AM BerggreenDK yes, we have some bad(expensive) dual-sided alpha planes used for leafs on trees. Have thought of doing them as a "face the cam" plane instead and reducing the numbers. Sep 19 '11 at 07:59 AM BerggreenDK add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x4179
x815
x78
x16
x12

asked: Sep 18 '11 at 09:03 PM

Seen: 1056 times

Last Updated: Sep 19 '11 at 07:59 AM