- Home /
Question by
MathijsF · Oct 25, 2019 at 12:02 PM ·
c#procedural meshgarbage-collection
Can I reuse a vertex list after calling mesh.SetVertices()?
As the title.
I procedurally create a new mesh (through new Mesh()). Then create a new List for vertices. Then call mesh.SetVertices(vertices).
Can I now do anything I want with that List object? Like pooling it, etc.
Or do I have to destroy the mesh first?
Comment
Best Answer
Answer by Bunny83 · Oct 25, 2019 at 01:32 PM
Yes you can. The data in the list is only copied into the native vertex buffers. Unity does not keep a reference internally to your List. Once the SetVertices returns Unity does not touch the list anymore so you are free to re-use it.
That's one of the main points why Unity now provides most mesh manipulating methods with Lists instead of arrays so it's easier to reuse the list and avoid unnecessary garbage / garbage collection