- Home /
Avoid Mesh Sharing
I have a component script that create and setup a quad and store it in the MeshFilter.SharedMesh of the gameobject ( since we are allowed to use mesh directly ).If I have this component attached to a gameobject and I copy / paste the gameobject in the editor both gameobject will share the same mesh, but I would like each instance to have their own mesh so I could set different parameter for each of them.
Answer by Joyrider · Aug 05, 2013 at 10:54 PM
you just have to call MeshFilter.mesh on each copied gameobject for it to create a duplicated mesh instance of the mesh. You don't even have to assign it, just the call is enough to have a duplicate created and used instead of the original.
Answer by kupo · Aug 06, 2013 at 08:28 AM
Hello, Thanks for your answer.
When I use mesh it works perfectly but unity raise an error saying that I'm leaking mesh and I should use SharedMesh instead, do you know how to get ride of that ?
No, I'm guessing it is a failsafe, so people would rather use shared$$anonymous$$esh, since they rarely tend to modify the mesh and wish for seperate meshes. But it is imho technically not an error, unless you create meshes that aren't referenced by anything.
Well I tend to think that this error is here for a reason, I have to find a way around since I cannot be sure that ignoring the error will not cause further error in the futur.
Thanks
Indeed, it is there to avoid meshleaks, which is what it does when the instantiation is unintended. Anyway, then all that left is for every copied object to instantiate the mesh manually and assign it to the meshfilter