2 Meshes sharing same animation through one bone system / character controller?

Hi!

Is there any way to have 2 meshes (i.e. character mesh and clothing item mesh), share the same character bone system/character controller? If both the character mesh and clothing mesh (that goes on top of it) are skinned and animated from the same rig, shouldn’t that mean that they can share the same controller somehow? Is this something that can be achieved though scripting, or some other means?

Any kind of direction on the matter would be greatly appreciated. thanks!

I just recently figured this out. It’s semi-easy (conceptually).

Each bone in a mesh’s armature is just a transform.

Thusly: Take the bones of a shirt or whatever, and make them parented to the corresponding bones in the main body.

Little bit harder in practice to set it up right:

I wrote some scripts to help with this. They ONLY work if the parent and child mesh have the EXACT SAME ARMATURE. Otherwise they will break. Also, they must have the same ‘origin point’, ie, if they are dragged into the scene to the same spot, it would appear that they were parented.

Child objects should not have any animation. Only do animations on the parent.

So, ideally, to set up your models to work with this correctly:

Make a character in the ‘default clothing(underwear)’. Make sure you completely rig them and everything, so the only thing left for them is to be animated. After this point, you cannot under any circumstances change the rig.

Duplicate the file, for each clothing piece. In said files, replace the character’s mesh with the clothing. It kind of helps to keep the characters mesh if your program can copy mesh weighting information from one mesh to another, also so that you can also make sure the clothing completely covers the character, but don’t export the character mesh in to unity, just the clothing piece.

Animate the original character file, and only this file. You do not need to copy animations to other files/clothing pieces.
Keep an ‘unanimated’ copy somewhere on your drive if you’re thinking of keeping it to add more clothing pieces later. (cause you don’t want clothing pieces to have animations)

Bring everything in to unity, and make prefabs for each clothing piece, that includes the skinchild script on the root piece, with the variables as assigned. Remember, there is an ‘autopopulate’ function that you can run by clicking on the arrow for the script, and it will fill out the bone transform array. All of the bone transform arrays should turn out the exact same if you did everything correctly up to now. Make a prefab for the character model, also filling in the correct fields, but while using the skinparent script. It’s bone transform array should also be the exact same.

During runtime, if you want to instantiate a character with some specified clothing, merely spawn the character, the correct clothes, and then attach the skinparenter script to the character, and assign the values. Something like:

var skiPar : SkinParenter = parentObj.AddComponent(SkinParenter);
skiPar.parentM = parentObj.GetComponent(SkinParent);
skiPar.childM = new SkinChild[(number of clothing objects)];
skiPar.childM[0] = clothingObj1.GetComponent(SkinChild);
(etc for the rest of the clothes to fill the childM array)

. Before the frame is updated, the character and all the clothes should parent to each other, and in the correct position, as the Start function of the skinparenter parents all the clothing bones to their respective bones in the character’s armature.

Possible issues:
*Bone transform arrays are not the same after autopopulating: I doubt this will happen, but can be fixed manually if you still have the same number of bones. It’s just that each bone transform array on each piece needs to be the exact same as the skinparent’s bone array (order and everything).
*The character mesh seems start out in a different pose than the clothing, so the clothing gets parented in a weird spot: make sure that everything starts out in the exact same position/pose, including the character. It might be possible to fix this by changing a line in the skinparenter script to actually move each individual bone as it’s being parented to a 0 position and identity rotation, but I haven’t tried this out.

415640–14393–$SkinChild.js (618 Bytes)
415640–14394–$SkinParent.js (621 Bytes)
415640–14395–$SkinParenter.js (969 Bytes)

hey thank you so very very much for the in-depth and detailed explanation and solution! I’m happy to say that it works great! I have an extra questions, perhaps you can enlighten me further.

  1. The auto-populate function you speak of…how do you ‘run’ it? i found i had to manually insert the bone array myself for the time being…am i missing a step in actually doing it? or am i to do it manually?

  2. So i guess that means all clothing items have to be a ‘Skinned Mesh’ and be exported with the identical bone system as the character mesh. (just a clarification)

Otherwise this really was what I needed! I am grateful for the reply and I’ll be sure to refer to this in the future.

click on the gear, as circled on the attachments.

419947--14570--$popinst1.PNG
419947--14571--$popinst2.PNG

I kind of didn’t say anything about ‘unparenting’ an object, as someone has asked me about this. Add the following code to SkinParenter.js

This will NOT preserve the heirarchy of the original child. It will merely remove the child from the parent. I’m assuming I was asked this because they want to have a ‘character customizer’, where the children would have to be removed in order to try out the different ‘clothing’

function DeParentChild(dChild : SkinChild){
	//this is just to check if the child given exists in the array. You COULD remove this, but this is kind of a safety measure
	var foundChild : boolean = false;
	for (var foo : SkinChild in children){
		if (dChild = foo){
			foundChild = true;
			break;
		}
	}
	if (!foundChild) return; //this child doesn't exist. exit.
	
	//we have this child parented currently. Now deparent it. This does not preserve heirarchy of the old object.
	dChild.objRoot.parent = null;
	for (var tB : Transform in dChild.bones){
		tB.parent = dChild.objRoot;
	}
	
	
	//now remove dChild from the children array
	var nArray : SkinChild[] = new SkinChild[children.length-1]; //new array
	//copy the children still in the array to the new array
	var j : int = 0;
	for (var i : int = 0; i < children.length;i++){
		if (children[i] != dChild){
			nArray[j] = children[i];
			j++;
		}
	}
	//now set children to the new array
	children = nArray;
}

I had this concept that if you created a single armature in 3ds Max, then made it do all the animations, you could simply skin it with only the sections of clothing you want to appear. When you want to replace something, simply load a different part, and replace it. Say like WoW characters for instance, there are a million different outfit parts, but they are segmented into different models.

The reality is even simpler, Your base has your core animation (what you are doing) then you simply match the transform from each part, and the animation sequence, frame by frame, So even though the arm and body are 2 different pieces they move as one.

You have to be really conscious when creating artwork and how it is skinned. edge verts can NEVER be moved by more than 1 bone, so you always have a point of reference to go by. Mostly, this wont matter because they are static areas anyways, neckline, shoulder to pit and stuff like that.

So a system like this would be ideal for a game which would have many characters on screen at once… How would Unity hold up to lets say 20-30 characters using this system all on screen at once?

So i realize these scripts are kind of old, i was trying to use them and i get these console errors i cant figure out.

Assets/Scripts/$SkinParenter.js(15,27): BCE0018: The name ‘SkinChild’ does not denote a valid type (‘not found’). Did you mean ‘UnityEngine.SkinQuality’?

Assets/Scripts/$SkinParenter.js(2,15): BCE0018: The name ‘SkinParent’ does not denote a valid type (‘not found’).