I need to show a variety of performance metrics inside my built project (It’s kinda a tech demo)
In the editor, the stats windows displays a bunch of really useful stats, including Tri & Vert counts, however, as far as I can tell there’s not a way to show this window / get the stats inside the built executable?
Is there any way to get these stats (Just vert/tri count would be fine, but the draw calls etc would be useful aswell!) and display them ingame? Thanks!
I'm not sure if you need to manually typecast Object.FindObjectsOfType() to MeshFilter[]. If that's the case, then you could do this instead: int triCount = 0; int vertCount = 0; Object[] allMeshFilters = Object.FindObjectsOfType<MeshFilter>(); foreach (Object o in allMeshFilters) { MeshFilter meshFilter = (MeshFilter)o; //force o to get typecast to a MeshFilter if (meshFilter!=null && meshFilter.enabled) { triCount += meshFilter.mesh.triangles.Length; vertCount += meshFilter.mesh.vertices.Length; } }
– nesisWon't this show the number of verts/tris in total though, not the amount being currently rendered?
– JacobKIf you want the amount currently being rendered, you'll need to be a bit tricky. You'll need at attach a script to every MeshRenderer's GameObject, containing a method called OnWillRenderObject() (it gets called once for each camera that will render the object). You'll need to have static variables in this script to track the two counts, and add to them inside OnWillRenderObject(). Then in another script you can call MyScriptName.triCount and such to get those values for display, then reset them to 0 for the next frame.
– nesisTo figure out if any part of a mesh is being rendered by some camera, you can check the renderer.isVisible flag.
– robertbu:) but that'd be the smart way to do it.
– nesis