View triangle count of a scene?

This one’s probably a kind of noobish question, but I’ve looked all over and can’t seem to find an answer. Does Unity have a feature or a script to view the total number of triangles in a given scene? I found this script: http://wiki.unity3d.com/index.php?title=PrintPolyCount but it only shows the triangles on the object it’s attatched to, which isn’t very helpful.

Have you looked at the Stats? When playing a game in the Editor, click the Stats button in the top right. It’ll give the number of tris that are being rendered/calculated.

It’s not exactly what you’re looking for, though. Any particular reason you want to know all triangles in the whole scene?

As for me I’d like to know triangles count just to estimate scene weight without making build. When building for android every polygon counts. When importing assets from Asset Store or other sources sometimes happenes that few of them are not optimize at all. I realize that much more than only polycount affects scene weight, but it also gives some estimation.

I’d just created EditorScript to log selected GameObject’s polygons.

using UnityEngine;
using UnityEditor;

public class Polycounter : Editor
{
    [MenuItem("GameObject/Count Polygons")]
    public static void CountPolygons()
    {
        GameObject go;

        Object prefabRoot = PrefabUtility
            .GetCorrespondingObjectFromSource(Selection.activeGameObject);

        if (prefabRoot != null)
            go = (GameObject) prefabRoot;
        else
            go = Selection.activeGameObject;

        MeshFilter[] meshFilters = go.GetComponentsInChildren<MeshFilter>();
        int polyCount = 0;
        foreach(MeshFilter meshFilter in meshFilters)
        {
            Mesh mesh = meshFilter.sharedMesh;
            polyCount += mesh.triangles.Length / 3;
        }

        if (meshFilters.Length > 0)
            Debug.Log("Object " + go.name + " contains <b><color=yellow>" + meshFilters.Length
                + " meshes </color></b> with total <b><color=red>"
                + polyCount + " triangles</color></b>");
        else
            Debug.Log("<b><color=green>Object " + go.name + " does not contain any mesh - keep looking</color></b>");
    }
}

Howto:

  • create new script ‘Polycounter.cs’ in Assets/Editor
  • replace script’s body with code above
  • right click on GameObject you want to inspect and select “Count Polygons”
  • result will appear in the Console window

To count all polygons on the scene just put everything into one GameObject and inspect it.
I hope You have fun :slight_smile: