Bake cloth simulation from Blender to Unity?

Hi all,

I am trying to implement an opening curtain in Unity. It covers a window and when the player clicks on it, it will move to one side. Since it doesn’t need to be dynamic I made the simulation in Blender (because navigating the space and setting things up feels easier for me than using Unity for that task.
Now I got 200 frames of curtain animation but don’t know how to get this mesh animation to Unity. Most tutorials deal with armatures or bones and the importer in Unity does not recognize the baked animation in the FBX file. I tried a recommended way to export and import as .mdd file in Blender that creates shape keys for every frame but those aren’t recognized as well.

Any ideas for me?

Thanks! :slight_smile:

1 Like

One idea that might work is that you could tween between meshes that you import so that they have same point order.
This would also allow you to only have the amount of keyframes (meshes) you need. I’m not sure how fast this might perform and if it’s good idea for your use-case, but certainly doable. But you would need to write / or get some code for this.

1 Like

Thanks, this is a nice idea but more suited to a handful of meshes, I guess I would need a lot of meshes because the simulation is not very “linear” to tween. It would surely work, I could even switch the whole mesh every frame, but it sounds like a “hack” :slight_smile:

Have you figured it out? Thank you

Thanks to a video tutorial I was able to bring a shape key animation to Unity:

But it is not complete for dealing with cloth, I learned how to make shape keys from cloth simulation using mdd exporter: keyframes - How do I use shape keys to bake a soft body animation? - Blender Stack Exchange

So it worked, now I am putting everything together and simulate and export a real curtain with wall fixtures etc., import it in Unity, check if I can trigger the animations with an animator controller and if that works, I will try to post the solution here again. :slight_smile:

bossysinfularmyworm

So that is the final result so far. It has way too many polys but I don’t care right now :smile:
I hope I will find the time to make a small video tutorial about that at the weekend. The key to success was to delete the cloth modifier before exporting (but of course have the shape keyframes from the mdd import) and in the fbx export settings UNCHECK NLS strips and All actions.

3 Likes

Hello Olipool this curtain is really looking great I am wondering have you found a time to make a small tutorial video about that =) If you could you share it with me :smile:

Hi Batuhan, thanks for the compliment :slight_smile: I had to solve so many problems in that game that I had no time to make one tutorial so far. But thanks for the reminder, I hope I can make it this week, won’t be very polished but will show the steps needed :wink:

1 Like

Batuhan, apologies for the delay. I prepared the steps of the tutorial and will record it tomorrow :slight_smile:

1 Like

Alright mate I am waiting excitingly :smile:

Finally, it is finished, hadn’t thought it would take that long to make, cut and upload for such a short tutorial :wink:
Some right-click menus in Unity are not shown, I don’t know why, must be an issue with the capturing software. But if anything is unclear feel free to ask :slight_smile:

7 Likes

Wow, amazing! I was googling for the EXACT same answer, and here it is, I mean, you even made a vid tutorial about the solution! Holy crap, it’s fantastic!

1 Like

Haha nice, thanks for the feedback, then the work was worth it :wink:

Works like a charm thank you for sharing!

1 Like

Bonjour est ce que ça marche avec une armature sur un maillage personnage et plusieurs animations idl et marche par exemple?

Il “devrait” fonctionner avec tout ce qui déforme un maillage. Mais si vous l’utilisez pour des vêtements par exemple, il n’interagira pas avec le personnage et autres.

Hi Olipool! I followed your tutorial (thanks for making it btw), but when I go to remove the cloth modifier or subdivide modifier, the fabric doesn’t keep its shape anymore. I’m not sure what I’ve done wrong, I exported and imported the mdd as in the video, and the shape keyframes all show up…

Hi neetikumar21,
I haven’t tried to make a curtain since then so maybe the new Blender version or plugin of the export may have changed. It sounds to me like the keyframes are not containing the right things. I am just guessing but maybe on exporting, the curtain was not selected or something like that or some setting needs to be turned on. Maybe you need to apply the modifiers now before exporting. Maybe you can try that. If the shape key contains data for the curtain I don’t know why it wouldn’t “deform” the curtain each frame.
And did you bake the animation before exporting?