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
1
Question by stevosaurus · Aug 26, 2010 at 12:44 AM · gameobjectmeshmemoryproceduralvbo

Memory problems with procedurally generated meshes

Hello!

I am new to Unity and me and have run into a problem that I can't solve.

I am generating my games terrain procedurally, and storing the meshes for the terrain in several different game objects. I don't use one big mesh because I want to be able to quickly update one part of the mesh at runtime.

I am reusing gameobjects to hold new terrain as you move through the world and I repopulate their meshes with this code:

Mesh mesh = GetComponent<MeshFilter>().mesh; mesh.Clear();

mesh.vertices = vertArr; mesh.normals = normArr; mesh.uv = texArr; mesh.triangles = indArr;

mesh.RecalculateNormals(); mesh.RecalculateBounds();

This works well, but uses more memory every time I redo the mesh. Looking at the stats window it seems that my VBO total and the ram associated with it is probably the culprit. Looking at the profiler, my mesh number is always the same but the mesh memory increases with the VBO memory.

Is there anyway to get around this? Is assigning mesh.vertices several times just a bad idea?

Thanks for your help!

UPDATE: I followed Jesse's advice and switched to using sharedMesh. It solved my high VBO count problem, but VBO memory still seems to be an issue.

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
1

Answer by Jessy · Aug 26, 2010 at 01:19 AM

GetComponent().mesh creates a new mesh instance. Use sharedMesh instead. And you only need to run your first line once.

Also, are you sure you need to run these?

mesh.normals = normArr;
mesh.uv = texArr;
mesh.triangles = indArr;

For example, RecalculateNormals() takes care of the first one; unless normArr is just a way for you to change the size of the array. The other two may be necessary, but only if you're doing something that doesn't mimic Unity's heightmap-based terrain engine.

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 stevosaurus · Aug 26, 2010 at 02:03 AM 0
Share

Thanks for your response Jessy. I switched my code to use the shared$$anonymous$$esh property and that solved my ever increasing VBO problem. I am still seeing the same memory consumption though. Do you have any ideas why? If I do not assign any of the mesh properties (vertices, uv, etc..) then I do not have any memory issues, so I think my arrays are being picked up fine by the GC. Thanks again!

avatar image
0

Answer by madscience2728 · Sep 01, 2020 at 12:30 AM

@ConFliX @stevosaurus Hey there, I found my problem was I not nullifying the arrays I used to generate the terrain data and triangles. I went from 6 gigs down to 600 megs, because it was all in GC alloc. I find my meshes not a problem at all even at 1,035,050 triangles for 9*9*5 32x32 chunks

For Google's indexing bots: Unity mesh memory leak problems garbage collection gc alloc mesh triangles help problem procedural procedurally generated terrain

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 madscience2728 · Sep 01, 2020 at 12:30 AM 0
Share

I know this was a decade ago, but I mean still valid help aha

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

Can I use bytes instead of floats for vertices? 1 Answer

Modifying just one mesh and not all instances? 2 Answers

what is GameObject Structure? 1 Answer

How do you use the Plane struct 1 Answer

Mesh memory leak 3 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