I’m doing continuous procedural mesh generation and I want each object to have its own mesh displaced every frame should I use mesh or shared mesh? I don’t want to create a new mesh every frame only to edit it but every object needs a unique mesh instance.
Use mesh and not sharedMesh.
The SharedMesh property refers to your actual mesh asset, so changes to the mesh will affect all objects that use that mesh reference, and (I think) changes will apply to the mesh asset in your asset folder with running in-editor.
The Mesh property will apply to the “mesh instance” created for this specific object. The first time you access the “mesh” on an object, a new copy of the mesh will be created for you to modify. All additional times you access the “mesh” on the same object, you will get the same mesh that was created for you the first time you tried to access the “mesh” on this object. Since each object has it’s own instance, edits will only apply to the one object.
More detailed info, if you want:
Thanks for the clarification I have already read the documentation but it wasn’t clear to me wether calling meshFilter.mesh would generate a new instance every frame. I thought that I should call mesh the first time to create the unique instance and then sharedMesh to edit it.
Chiming in to say that I think the answer above is not necessarily correct.
I use sharedMesh by default unless an object absolutely needs its own copy of a mesh. This avoids the inefficiency of making unnecessary copies of meshes, which is especially useful in a procedural generation context.