Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by tunnuz · Oct 14, 2010 at 02:23 PM · verticespolygon

How to get the number of vertices, triangles programmatically?

Hello, is it possible to get the number of vertices, polygons programmatically, e.g. as written in the statistics inside the Unity editor? If so, how?

My fault, badly answered question. Should have been: is it possible to get the number of vertices, polygons in the whole scene programmatically?

Thank you

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Adam Rademacher · Oct 14, 2010 at 02:28 PM

Mesh.vertexCount
Mesh.triangles.Length

EDIT: Try this (C#):

int totalVertexes = 0; int totalTriangles = 0;

foreach(MeshFilter mf in FindObjectsOfType(typeof(Meshfilter)) { totalVertexes += mf.mesh.vertexCount; totalTriangles += mf.mesh.triangles.Length; }

Note: this is a very expensive call, so you probably don't want to run it often.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tunnuz · Oct 14, 2010 at 03:00 PM 0
Share

Hello, thank you for your answer. However, how to get the number of vertices and polygon in a scene at a certain moment? Or, how to get the mesh object for each object in the scene?

avatar image Adam Rademacher · Oct 14, 2010 at 03:43 PM 0
Share

Edited to add functionality that should help you.

avatar image tunnuz · Oct 14, 2010 at 03:48 PM 0
Share

Thank you again.

avatar image
7

Answer by PatHightree · Oct 25, 2011 at 09:02 AM

A correction on Adam's answer :

 meshFilter.sharedMesh.vertexCount
 meshFilter.sharedMesh.triangles.Length / 3

The triangles list contains 3 vertex indices for each triangle, so it needs to be divided by 3. I'm using sharedMesh here because Unity complains of leaked objects when the mesh is used.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by FZ_Applications · Jun 27, 2019 at 10:44 AM

Just to complete this: You can use UnityEditor.UnityStats.triangles (also vertices, batches, ...) But this not works in built games

I use it that way: (https://docs.unity3d.com/Manual/PlatformDependentCompilation.html)

 #if UnityEditor
 Debug.Log(UnityEditor.UnityStats.triangles);
 #endif
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Detect perimetral walls of a room 1 Answer

Selecting a single polygon / face at runtime 1 Answer

Vertex count 10 times higher in Unity 5 Answers

how to: create a four vertex, two tri square polygon in Unity Editor or Script? 4 Answers

City model for iOS game. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges