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
1
Question by gapMindful · Sep 21, 2016 at 07:01 PM · meshmemoryprocedural meshgarbage-collection

Native Mesh Access

I'm playing around with a lot of at runtime mesh generation. One of my last big performance hang ups is the GC after rebuilding the mesh frame to frame. Changes to the array sizes associated with the mesh require a new allocation. I could get around allocating new Mesh vert / uv / tri arrays by using some form of buffer. However, the Mesh API doesn't allow expose a count field for either array or access to the underlying native fields.

Has anyone found a way to access the native properties of Mesh or have any ideas on how I could avoid re-allocating verts/tris/uvs when making mesh updates?

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 Bunny83 · Sep 22, 2016 at 01:26 AM

In the past the only way around memory allocation was to create the arrays large enough. Left over vertices require space but don't affect performance. The triangle array can also hold more than required elements. When two of the 3 indices are the same the triangle is a degenerate triangle which isn't rendered at all. Of course there is a slight overhead for those triangles but it's almost nothing.

However Unity now introduces the methods: SetVertices, SetIndices and SetTriangles. There are also variants for setting colors and UV coordinates. (For some reason the documentation seems to be currently broken). Those methods take a generic List instead of an array.

Strangely they only implemented "GetUVs" to work with a List instead returning an array. Though setting is much more important anyways ^^.

Comment
Add comment · Show 1 · 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 gapMindful · Sep 28, 2016 at 05:42 AM 0
Share

Thanks for passing along the new setter methods. I finally had a chance to play around with this and unfortunatly it looks like there is still some sort of copy going on under the hood using the setters for vert/ tri/ uv. The meshimplementation around the setVerts method looks like it copies the provided list in some form, since updates to the referenced list after set don't appear to be reflected.

If I construct a vert list reference up front, set the vert list and then cache out the list reference to modify during future frames, the rendered mesh never reflects these changes

//Inside update loop each frame when mesh changes are flagged if (isFirstTimeThrough) { currentVertsList = new List(); mesh.setVertices(currentVertsList); } modifyVerts(currentVertsList);

However if I move the set line out and past the modify line above, so that the set would be called each frame, the mesh does reflect changes since the list contained the updated values when set. The problem I hit now is that there appears to be a major performance impact associated with calling the set, making me think there is another copy happening in unity's native mesh logic.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Efficient access to Mesh arrays 1 Answer

How can I remove redundant vertices in custom mesh? 0 Answers

Perlin Resources system 1 Answer

SpriteSheet/Mesh Hybrid to reduce overdraw on iOS? 2 Answers

Can and should a procedural mesh be shared between multiple GameObjects 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