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 JacobK · Mar 07, 2014 at 01:06 PM · performance metrics

Display current vertex/tri count drawn in game (When built)

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!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by nesis · Mar 07, 2014 at 01:19 PM

 int triCount = 0;
 int vertCount = 0;
 MeshFilter[] allMeshFilters = Object.FindObjectsOfType<MeshFilter>();
 foreach (MeshFilter meshFilter in allMeshFilters) {
     if (meshFilter.enabled) {
         triCount += meshFilter.mesh.triangles.Length;
         vertCount += meshFilter.mesh.vertices.Length;
     }
 }

Warning: This could be a slow process if you have a ton of meshes at runtime!

Comment
Add comment · Show 5 · 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 nesis · Mar 07, 2014 at 01:22 PM 0
Share

I'm not sure if you need to manually typecast Object.FindObjectsOfType() to $$anonymous$$eshFilter[]. If that's the case, then you could do this ins$$anonymous$$d:

 int triCount = 0;
 int vertCount = 0;
 Object[] all$$anonymous$$eshFilters = Object.FindObjectsOfType<$$anonymous$$eshFilter>();
 foreach (Object o in all$$anonymous$$eshFilters) {
     $$anonymous$$eshFilter meshFilter = ($$anonymous$$eshFilter)o; //force o to get typecast to a $$anonymous$$eshFilter
     if (meshFilter!=null && meshFilter.enabled) {
         triCount += meshFilter.mesh.triangles.Length;
         vertCount += meshFilter.mesh.vertices.Length;
     }
 }
avatar image JacobK · Mar 07, 2014 at 02:37 PM 0
Share

Won't this show the number of verts/tris in total though, not the amount being currently rendered?

avatar image nesis · Mar 10, 2014 at 02:19 AM 0
Share

If you want the amount currently being rendered, you'll need to be a bit tricky. You'll need at attach a script to every $$anonymous$$eshRenderer'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 $$anonymous$$yScriptName.triCount and such to get those values for display, then reset them to 0 for the next frame.

avatar image robertbu · Mar 10, 2014 at 02:23 AM 0
Share

To figure out if any part of a mesh is being rendered by some camera, you can check the renderer.isVisible flag.

avatar image nesis · Mar 10, 2014 at 02:51 AM 0
Share

:) but that'd be the smart way to do it.

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

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

iOS performance problem (iphone 4 on iOS6) 1 Answer

Reading Profiler Results 1 Answer

How does rendering mode affect the number of tris and vertices drawn? 0 Answers

How to improve my game performances on mobile devices 0 Answers

Collecting performance data 0 Answers


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