- Home /
sharedMesh - what is the mesh shared with?
The Manual is not clear on the difference between .mesh and .sharedMesh - other than that the latter should be read-only... What is the sharedMesh shared with?
Answer by Jessy · Dec 29, 2010 at 01:08 AM
Let's say you have a whole bunch of the same non-skinned* object on-screen. All the objects could use the same mesh. But as soon as you do anything to modify MeshFilter.mesh, on one of them, the mesh gets instanced, allowing for that object to have changes applied, while the others stay the same. This allows for you to make changes to a saved mesh, in-game, without having to save a whole bunch of similar meshes with the scene. If you make changes to MeshFilter.sharedMesh, however, every object will have the same changes applied. Each of these variables can be very handy if you're making use of prefabs.
Also, if you procedurally create your own mesh, and save it in the Assets folder, the changes you make to a "sharedMesh" will be persistent. This doesn't happen with meshes in FBX files, which will be reset at some later point, after modification. I honestly don't know the rules regarding the timing of the FBX resetting, but regardless, it's not useful unless you're in Play mode.
*For whatever reason, you can't instance a skinned mesh in this fashion.
So, shared$$anonymous$$esh is kind of like a prefab for mesh...
Also, I am not sure what the caveat mentioned in the shared$$anonymous$$esh manual page refers to, "Also, be aware that is not possible to undo the changes done to this mesh." ... as long as you cache the changes to the mesh, you should be able to revert, right?
Yes, but that's not "undo", in the sense of the Edit menu type of thing. Also, as far as I can tell, that warning is basically a lie. Even just saving a scene or restarting Unity will revert the mesh back to its originally-imported state, in my experience.
I just found out what they meant by no-undo on mesh.. If you edit a shared$$anonymous$$esh procedurally, it'd apply the changes permanently to your scene object!!! Replacing the .mesh in paintvertices.js procedural example with .shared$$anonymous$$esh i found that after pressing play, the changes remain!! I saved the scene, restarted, and my sphere is this still this deformed paintvertices ugly sculpted thing!!!
Are you just using the default Unity sphere? That would make sense, because it doesn't have an FBX file to reference.