I downloaded the model from the internet, baked the textures, exported the fbx to unity. But when I tried to animate the character, the clothes behaved differently than in blender. I searched for a long time for solutions, for example:
Turned on all sliders in the geometry window when exporting the model
Turned off “Add leaf bones”
I went to Unity: Edit → Project settings → Quality → Skin Weights and set 4 bones there.
Ran through the clothing and body models and enabled 4 bones there.
Cleaned all modifiers on the model, except for the armature itself
In Import Settings I put “Import” wherever possible.
I switched between “Humanoid” and “Generic” structure
I don’t know any more ways to fix it. In other cases I’d blame it on the shoddy Weight Paint model, but it works perfectly in blender and it’s when importing fbx into Unity that the problems appear. I can’t understand: am I exporting the model wrong or is Unity artificially applying some optimization techniques I don’t know about? Blender:
In high-finesse situations like this, the limitations of a game engine will become apparent.
If your clothing is driven by nothing but bone deformations, then the answer is almost surely that your cloth is being influenced by more bones than you think. Blender can spend as much time as it needs to carefully calculate the vertex position after being influenced by 5, 6, even 12 bones. Unity, to simplify the math and make it more predictable and optimized for game characters, will reject influences beyond the 4th bone. That is, if a vertex belongs to more than 4 groups, it figures out the most impactful influences and remove the vertex from all other groups.
The answer is generally to iterate through the import process. Sharpen up the gradients of your vertex weights so it will resemble the imported 4-bone-max more closely and predictably. Your clothing topology does not match your body topology, so add some extra thickness to the clothing to avoid the uneven shrinkage. Poke the skin lower and pull the cloth higher in tight areas. Where there’s a polygon of skin that can never actually be seen, remove it. Add more topology in the flexing areas.
The alternative, if performance is not an issue, is to look into cloth simulating code assets on the store. Magica Cloth 2, or Obi Cloth, for instance. It’s a whole different learning curve, but can often make far more eye-catching second level motions than modeling a fixed mesh-and-bone wardrobe.
Thank you. Your answer almost explained me everything about the weight in Unity. And yes, I have been doing Magica Cloth for a long time and know how to do it with it. But is there any way (plugin or customization) to bypass the 4 weights limit? It seems to me to expand the limit to 8 for example would be much better for performance than to make 100 colliders on 1 thigh only, so that this dress for example could interact with it normaly?
The SkinnedMeshRenderer code is all closed source as far as I know. To my understanding, Blender needs one quaternion multiply per weight * bone, and since these quaternions are dedicated to each bone, you can string along all the multiplies you want, at a cost of efficiency. Conversely, Unity batches it up ahead of time into 4x4 matrices, so one matrix multiply handles four weights at a time… and therefore can’t be chained as easily. I don’t know the details. Maybe it could still be done. Maybe somebody at Unity is still familiar with this decade-old code and can wring out new life. Maybe we’ll win the lottery next week.
Also, you might be exaggerating about the 100 colliders, but if not, you should also check out an asset called Technie 2. Whether you buy it or not, look at their videos to see the approach of choosing subsets of a skinned mesh that don’t flex much, to form convex mesh colliders. You can definitely get your collider count down to about one per long bone.
Oh, I might be behind the times, as there is a “Blend Weights” choice in the Project Settings > Quality area. Apparently this lets you choose 1 bone, 2 bones, 4 bones, or Unlimited (at the expense of performance of course). I’ve never used it. Try this option to see how much it affects your model. It may still suffer from other differences in math.