- Home /
Assigning a clothing object to a character's skeleton?
I am trying to do an equipment system where there are interchangeable clothing items that get instantiated onto the player as they are equipped, as is standard in most RPGs. So far I've got the position of the clothing after they're instantiated fine, but I can't figure out how to get the clothing to animate.
I've read that I should set the root bone of my clothing object's skinned mesh renderer to the root bone of my character. However, that seems to only allow the transforms of the root bone that I assign (the "hips" bone in this case) to actually affect the mesh. Sometimes it even causes weird offsets in the position of the mesh as well. I'm hoping I'm just misunderstanding something here, because I can't understand why it wouldn't work. Both the character and the clothing mesh were made with the same skeleton.
Am I going about this in the wrong way? There are only two other options I can think of. Copying all of the character skeleton's transforms to a skeleton that is on the clothing object (or parenting the clothing's bones to the character's), but that seems fairly complicated and inefficient. The second one being to play the same animation on each clothing object. That would mean having multiple skeletons animating at the same time, and wouldn't that cause a bit of a performance hit?
Been frustrating the past few days trying to figure this out with everything else in my game going relatively smoothly, and maybe I'm just overthinking it. Just thought I'd ask here for advice before I bite the bullet and just go with option #2 that I listed.
Bumping this question! I would also like to know the answer.
I'm not sure parenting clothing to a single bone (i.e hip) makes sense, as mesh vertices are often influenced by more than one bone so in that scenario I would expect oddities depending on the pose or animation; link to that?
http://docs.unity3d.com/$$anonymous$$anual/class-Cloth.html
When you add that script to the mesh you want animated, a Skinned $$anonymous$$esh Render will also appear,
http://docs.unity3d.com/$$anonymous$$anual/class-Skinned$$anonymous$$eshRenderer.html
You'll see there is a Property for Root Bone. When both OP and I apply the root bone of the hips, it causes the clothing to appear in an unnatural location in contrast to where the hip bone is actually located. (OP, are you using the $$anonymous$$ixamo rig by chance?)
I am using Rigify in Blender for my skeleton. I have a temporary (hopefully) workaround by manually adding bones to variables.
Answer by Cherno · Apr 05, 2016 at 06:36 PM
This UA thread explains how to map the bone array from the clothing mesh to the cahracter mesh:
Thanks for that link. I can't believe I didn't find it when searching for this a while ago. However, that doesn't seem to work for me, as the mesh just seems to disappear afterwards.
A comment in there suggested something so simple, I feel like an idiot for spending so much time trying to figure it out. After trying it... it works (although it seems to shrink the mesh of the clothing for some reason...)!
That answer was simply
object.GetComponent<Skinned$$anonymous$$eshRenderer> ().bones = target.GetComponent<Skinned$$anonymous$$eshRenderer> ().bones;
Answer by Disrar · Aug 05, 2015 at 03:32 AM
I've created a temporary workaround for parenting a clothing's skeleton to the character's, however it isn't ideal as I haven't figured out a way to find bones automatically.
I set up a script that contains Transform variables for each bone on the character,
using UnityEngine;
using System.Collections;
public class CharacterBoneList : MonoBehaviour {
public Transform Hips;
public Transform Spine;
public Transform Chest;
.
.
. etc for each bone
}
then call ParentClothBoneToChar () from a script attached to the clothing item that has variables for each bone as well:
using UnityEngine;
using System.Collections;
public class ParentClothBoneToChar : MonoBehaviour {
public Transform clothHips;
public Transform clothSpine;
public Transform clothChest;
...etc
public CharacterBoneList charBones;
public void ParentBonesToChar () { charBones=GameObject.Find("Player").GetComponent<CharacterBoneList>();
clothHips.SetParent (charBones.Hips);
clothSpine.SetParent (charBones.Spine);
clothChest.SetParent (charBones.Chest);
.
.
. etc, for each bone.
}
}
Of course this means having 4+ skeletons on each character since you need one for each article of clothing. I know that bones in Unity are simply GameObjects, but having over 4x than what is needed seems a bit inefficient to me.
Answer by LaJolly · Aug 05, 2015 at 06:21 AM
I found the answer! The clothing mesh needs to be skinned to the rig and imported along with the fbx.
Do you mean importing the clothing mesh, with the skinned rig attached, then deleting it and assigning the root bone to the one that your character is attached to?
Or do you mean keeping their own skeletons, then animating them at the same time as each other? That might be better than my current solution, but you still end up with multiple rigs being needed per character.
It's probably unnecssary to import the whole rig with the weight mapped mesh, but as long as your mesh contains the weight map information, it should work.
You need to actually skin your mesh clothing to the rig in a program like maya or blender. You need to have it "skinned" to use the "Skinned mesh render" properly. Skinned = Weight $$anonymous$$apping to the rig. The Unity Clothe physics seems to require at least some info in weight mapping to work right.
I just put the clothing on the character in $$anonymous$$aya, Smooth Binded the mesh to the proper joints, smoothed some of the weight mapping for more natural movement in the top of the dress, and exported it and the rest of my meshes and rig as a avatar.fbx. I then imported it into Unity and added the Physics competent script to the mesh that is intended to make use of the physics. You then need to edit the colliders and cloth constraints for polish.
Oh, so the character mesh and clothing mesh are in the same file? That does work for making the character and clothing item work with the same rig. However, the filesize of that file would become very large with dozens of clothing items added in. It may not be a problem since I create prefabs for the items anyways, and could separate them out.
All my meshes are skinned, I'm just importing them separately, each with their own rig. They work fine on their own, but when I try to parent, say, shirt to the character's rig, the only thing that seems to affect the mesh is the position of the root bone and not the arm bones. If I go through the process of parenting each individual bone from the shirt's rig to the character's rig, it will work. However, that's tedious and time-consu$$anonymous$$g. This is why I felt there was a better way, or at least a more automated way built into Unity to do the parenting.
Thanks for your help, you're giving me some ideas to try out. Just hope they work.
Well, did they work after all? I'm trying to do the same thing -and I'm a developer, not 3D modeler, so it's giving me a huge headache... A set of instructions would be ideal, if possible :)
None of the ones I came up with worked out, so I kind of tossed this to the side until now, even rewriting all of my inventory and item/equipment code. The solution I found was so simple though. See my comment under Cherno's answer. You may even be able to get the solution from Cherno's link to work for yourself as well.
Your answer
Follow this Question
Related Questions
Animating bones and the entire skeleton together 0 Answers
Can I restore bone locations in skeletal animation after the character was deleted? 0 Answers
How to separate bones from a 3dsMax skeleton? 0 Answers
creating a disolvable ik rig in blender for unity3D mecanim 0 Answers
scaling bone animation of salamander tongue looks fine in max but breaks in unity 1 Answer