Swap/combine mesh parts i.e. attach one skinned mesh to another via bone

Hi all,

I have a character, say, a robot that is customisable. He has many different mashes for hands, feet etc and they are interchangeable and have their own animations and textures. I want to be able to attach a part to another part and still retain its own animation and textures but move according to its new parent transform. For example I have a torso skinned mesh and need to attach an arm at the shoulder bone.

I’ve seen examples where people say to have one whole animated skeleton and then make parts with the same bone names for that part and replace them but the point is that one hand may have a different animation to another hand, I just need to make sure that the shoulder bone of the arm is attached to the shoulder bone of the torso so that it positions itself accordingly.

I’ve tried setting the parent of the root of the arm to the shoulder transform of the torso but it doesn’t seem to position itself correctly and the animation on the arm stops working, I’m guessing as the animation file is now looking at a different bone hierarchy. Although the arm does seem to move relative to the movement of the torso as it animates.

Any ideas on how to achieve what I’m after?

Am I just going to have to work out a way of breaking all the other meshes down and rebuilding a mesh from scratch in code with the sum of all the parts?

If you build and animate the main skeleton, and then parent the parts to the appropriate bones in that skeleton, there shouldn’t be a problem.

Something like this:

var part : InterchangablePart = GetPart();
var bone : Transform = skeleton.Find(part.attachBoneName);

part.transform.position = bone.position;
part.transform.rotation = bone.rotation;
part.transform.parent = bone;

You do have to build the parts with origin and rotation such that they match the bones’ default position. That might be what you’re seeing.