- Home /
poly and vertex counting at runtime
Hi all,
I'm trying to display at runtime (deployed app runtime) on the GUI the poly and vertex count visible on the camera and i came up with this:
using UnityEngine; using System.Collections;
public class GFXStats : MonoBehaviour { public GameObject[] allObjects; public float totalPoly; public int totalVertex;
// Use this for initialization
void Start()
{
allObjects = (GameObject[]) GameObject.FindObjectsOfType(typeof(GameObject));
}
void OnGUI()
{
string display = "polys: " + totalPoly.ToString() + " / vertex: " + totalVertex.ToString();
Vector2 dimensao = GUI.skin.label.CalcSize(new GUIContent(display));
GUI.Label(new Rect(Screen.width / 2 - dimensao.x / 2, Screen.height - 30, dimensao.x, 30), display);
}
// Update is called once per frame
void Update()
{
float polyCount = 0;
int vertCount = 0;
foreach (GameObject obj in allObjects)
{
Renderer rend = obj.GetComponent<Renderer>();
if (rend && rend.isVisible)
{
MeshFilter mf = obj.GetComponent<MeshFilter>();
if (mf)
{
polyCount += mf.mesh.triangles.Length/3;
vertCount += mf.mesh.vertexCount;
}
}
}
totalPoly = polyCount;
totalVertex = vertCount;
}
}
But the code is only counting the meshes totals. I was looking for the rendering totals (reflections, projectors, etc, increase those values) Any idea ?
Thanks in advance!
I wonder if they would be so proud of the Profiler in the PRO edition if this was possible just by scripting. As I see it Profiler is one of their sellingpoints for a PRO license.
Answer by Dreamora 1 · Oct 18, 2010 at 01:27 AM
There is no way to extract these information in the player at least not without installing NVIDIA PerfHUD and checking them there
PerfHUD and similar tools are a great way to benchmark, and they will give you much more info than just a vertex count. http://developer.nvidia.com/object/nvperfhud_home.html
Answer by duck · Mar 30, 2010 at 08:09 PM
You're aware of the Rendering Statistics Window in the Game View, right? It does all this. It's not available in your built version though, but since you haven't specifically mentioned that you're aware of it, and you also haven't mentioned built vs. editor runtime, I've just got to check!
sure, i'm aware about the stats window in the editor. I was looking to display those info in the deployed app runtime. Sorry, it is really confusing. I'm editing the question. Thanks anyway ;)
Answer by lustu · Oct 18, 2011 at 06:18 PM
I'm also interrested by this answer, and to be more specific, by the number of polygons actually displayed by the graphical card (i.e. including frustum culling)
Answer by FiveFingers · Apr 16, 2013 at 05:42 PM
Blitz3D a directx7 basic metalanguage used in far 2000 that costed 100$ had total vertices and triangles count in 2 simple api call. I can't get why Unity doesn't have such calls.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Debug Rendering using the depth buffer 3 Answers
Is there a way to have debug code compiled out for a final build? 5 Answers
Selected Mesh Polygon Count 4 Answers
My script isn't working - what are some ways I can start debugging? 7 Answers