unity – Automatically create capsule colliders from bones?

I have tried to automatically generate capsule colliders from bones by temporarily creating a mesh collider and using raycast to find the distance to it from the bone, but when I create the capsule collider there seems to be some rounding errors that makes them very big for bones far down in hierarchy. I am doing this to make cloth physics work.

Any suggestions what might be wrong? I have tried to convert to from global and local space to the best of my knowledge, so am wondering if the only solution is to flatten the bone heirarchy.