So, there were actually four things going wrong about the mesh and the armature:
- incorrect scale - this has made the model look stretched
- incorrect bone transforms in the base pose - this has made the model look twisted
- poor weights
- different skeleton proportions
1: Incorrect scale
Regarding the incorrect scale - not sure what has caused it, but, as @DMGregory has explained, if the offset between a bone and a joint is measured in metres (say, 1.3) but the animation thinks it's in millimitres - this would be like offsetting by 1300 metres. Which I think what was happening in the case - so it was kinda wrapping a mesh around a skeleton that is 100 times larger.
How I fixed it: in Blender where I was using metric system, I have scaled both the mesh and armature x100 and applied all transforms - after that, the problem of stretching was solved.
2: Incorrect transforms in the rest pose
After you fix stretching, you will most probably notice (if you are retargeting like me and using another skeleton) that body parts are all rotated in random directions. This is because every joint in the mesh has its specific transform in the rest pose. If those transforms in the Unreal's skeleton are different from your armature, the offsets will be applied to incorrect initial transforms which would cause distortions:
To put it short (because I don't understand the low-level mechanics properly): because the joint is rotated differently in the rest pose, animation will not work properly.
How I was trying to fix it:
a) in Blender 2.83, activate the following property as shown below to see bone local transforms:
b) import Unreal's skeleton or one of the animations available: in Unreal 4.22.3, you can do that by going to Animations, right-clicking a single animation and exporting as fbx. You can see how different those sekeltons look in regard of rotations:
You see that the bone translations/rotations are completely different for the unreal's skeleton on the left.
c) to fix it, you would have to rotate/move each bone manually in your 3d software. I never had patience to finish it (only did a couple of joints which has partly fixed the problem) but @MostHost LA on Unreal forms has brought it to its end, and it would look like this:
3: Poor Weights
As you can see, after fixing scale and joint transforms, this still look bad. The reason is that the weight paint isn't fine. I haven't done this part yet, but I guess you would import Unreal's animation, play on your character, stop at particular frames and fix the weight paint until it looks fine.
4: Different skeleton proportions
When you are done fixing weights, this will still look somewhat like the picture above. This is because the skeleton proportions are different. For example, my skeleton has narrower shoulders than the Unreal's skeleton. This means that my mesh would be stretched a bit in the area of shoulders to match Unreal's skeleton. I am pretty confident, there are retargeting tools in Unreal that can fix it automatically: check their YouTube channel if you ever need to go through the process.