Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 robinking · Jun 02, 2011 at 03:50 PM · meshperformancearrays

Is it faster to access an Vector3 array than to access a mesh's vertices?

I'm having some real slowdown in an app when it accesses a mesh's vertex positions. (It has to do this sometimes many times in one frame.) I want to try adding a separate array of Vector3's which will mimic the mesh.vertices array - and then use the separate array for reference, only accessing the mesh vertices when changing them.

Am I barking up the wrong tree here, or might this help my performance? I'm asking if there's any extra overhead in checking an entry in a mesh.vertices array compared with checking an identical array which is separate from the mesh.

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

2 Replies

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

Answer by robinking · Jun 02, 2011 at 04:30 PM

I've checked and using a stored separate array gives the much needed speed boost. For comparison I also tried Eric's method above, but because of the structure of my code, the function I call several times per frame copies mesh.vertices into a new Vector3 array and accesses that instead - so I still got the very bad slowdown I need to avoid.

Having a stored identical array (i.e. declaring it at top of file), and accessing that instead, was ~180X faster! Obviously it can only be used when referencing the vertex positions, not changing them, but that's all I need for my current purposes.

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
2

Answer by Eric5h5 · Jun 02, 2011 at 04:10 PM

Yes, you should do

 var vertices = GetComponent.<MeshFilter>().mesh.vertices;
 // do stuff with vertices
 GetComponent.<MeshFilter>().mesh.vertices = vertices;
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 robinking · Jun 02, 2011 at 04:33 PM 0
Share

Thanks Eric. However, the function I have which I tried that in is accessed many times per frame, so doing it strictly like you state means copying the mesh.vertices array many times per second, so still resulted in the slowdown. For clarity, I've put a separate answer as the key to it is permanently storing the copied array. I still gave you a thumbs up though!

avatar image Eric5h5 · Jun 02, 2011 at 04:36 PM 0
Share

Sorry for not being more explicit; I meant that you should do the GetComponent once, and use that array from then on, only assigning it back when needed. It wasn't intended that it should all be in one function, though I didn't make that clear.

avatar image robinking · Jun 02, 2011 at 04:40 PM 0
Share

Ah - good to have outside confirmation! Thanks again :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Re-meshing Static Objects as one mesh? 1 Answer

new Mesh() works outside of array, but not in array. Huh? 3 Answers

Does using the same Mesh variable for multiple Mesh Filters take up more memory? 1 Answer

Would combining meshes of 2D hexagons help my performace? 0 Answers

Best practices for a giant moving environement/enemy 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