- Home /
Can you make Mesh manipulations persistent?
I'm trying to develop a game together with 2 friends, only one of us is competent with drawing 3D Objects so he does all the modeling and hands us the .fbx files. Most of these files are a collection of objects which show up as a prefab in our scene. For example a ship where the rudder and cannons are all parts of the parent 'ship' object. However in some of the subobjects, the pivotpoint is wrongly defined and supposedly this is a lot of effort to fix in the modellingtool. I decided to write an editor extension to fix the pivotpoints in the meshes by editing the sharedMesh property.
However after closing Unity, the pivotpoints of the meshes are somehow reset. As far as I read in the documentation, modifying the sharedMesh property changes the actual model and should make it persistent throughout the project.
Is there something I'm missing to make the changes on the meshes persistent?
Try this: https://docs.unity3d.com/ScriptReference/EditorUtility.SetDirty.html or the alternatives described on the page which can be used to generate undo states.
Answer by EDamman · Nov 28, 2016 at 03:04 PM
I managed to find a solution, it's not very elegant, but it works in for my usecase.
Instantiate the mesh:
Mesh meshToSave = Instantiate(rotatable.GetComponent<MeshFilter>().sharedMesh) as Mesh;
apply the required operations to the vertices of this mesh, then create an asset from this mesh and save it.
Answer by jordys · Nov 18, 2016 at 03:36 PM
Check the following link: https://docs.unity3d.com/Manual/ModifyingSourceAssetsThroughScripting.html
Under 'Direct Modification', there is a script that you can use to permanently save changes to source asset files.
That is the way I implemented the modifying of the meshes. However when reopening the project, the changes are reverted.