stighy
stighy

Reputation: 7170

How to save modified mesh at runtime?

In my game, I modify mesh at runtime using a damage algorithm.

After that, I would like to save them.

I get all meshes with:

MeshFilter[] meshfilters = MyObject.GetComponentsInChildren<MeshFilter>();

then i modify single mesh.

How to save that in my original FBX file ?

Thanks

Upvotes: 0

Views: 3370

Answers (1)

Empty
Empty

Reputation: 516

Unity's internal mesh type is not the same as an FBX, FBX is a file storage format, while Unity uses a different internal structure at runtime, for greater efficiency.

As far as I know there is no standard way to save out a runtime mesh as an FBX (this is a feature of 3D modelling software, not a game engine)

You can save your deformations somehow and re-apply them when you reload the model, when I did a similar thing (custom generated terrain meshes at runtime) I would generate a mesh at runtime, then save the data required to generate that mesh, then pass it into the same flow I used to generate the mesh in the first place.

It is possible to serialise meshdata in the unity editor as meshdata is actually a different format from FBX (Unity reads an FBX, then generates a mesh asset from the FBX's data, then associates that mesh with the FBX) You do this by playing with AssetDatabase.CreateAsset() https://docs.unity3d.com/ScriptReference/AssetDatabase.CreateAsset.html

But I don't think this is what you're intending to do.

If you want the full FBX suite of features (skinning, animation, use in other unity projects) and you want them at runtime, you don't really have any options that I know of. Short of implementing your own FBX serialisation library (not really a reasonable solution)

Upvotes: 1

Related Questions