Animate clothes not related to character

Hello to all,

I hope someone can help me …

Basically I have a character that I anim via Animator and several “separate” pieces of clothing that were made with the same rigging.

What I’m trying to do is make the clothes move at the same time as the character so I created a script that mimics the position of each the character bones on the clothes bon.

The problem is that although it works there is a slight flicker (they are not perfectly synchronized , perhaps due to the slowness of the cycle).

Anyone have any ideas on how to synchronize the clothing with the character or how to improve the script?

Thanks in advance.

This is the script:

using UnityEngine;

public class BonesSync : MonoBehaviour
{
    [SerializeField] GameObject characterObj;
    Transform[] characterBones;
    Transform[] thisBones;
    SkinnedMeshRenderer dressRender;

    private void Start()
    {
        characterBones = characterObj.GetComponentInChildren<SkinnedMeshRenderer>().bones;

        dressRender = this.GetComponentInChildren<SkinnedMeshRenderer>();
        thisBones = dressRender.bones;
    }
    void LateUpdate()
    {
     
        for (int i = 0; i < thisBones.Length; i++)
        {
            thisBones[i].eulerAngles = characterBones[i].eulerAngles;
            thisBones[i].position = characterBones[i].position;         
        }
     
    }
}

I’m not sure there is a general solution for this… I don’t think skinning is necessarily transitive (or proportional? Not sure the right term).

What I mean is, if you have vertex A and C related to the player, and the clothing vertex B is located halfway between them, I don’t think B will necessarily always lie on the line AC as you skin them.

I adapted the technique described in this video to solve the same problem in my rpg.

This video shows it in action.

All the armour/clothing items were rigged using the same rig as the main character and then exported out of Blender as separate objects (each piece also includes the rig).

Once ‘stitched’ onto the character all the pieces are animated by a single animator (the one on the character model), so there are no synchronisation problems.

Thanks for the replies,

So, currently I solved it by duplicating the main character’s SkinnedMeshRender for the body parts where I have to match the clothes ( Jacket, Pants, boots ) and I removed the mesh and materials.

When I want to change a dress, I just load the dress mesh and its materials into one of the SkinnedMeshRenders that I have duplicated.

Previously I tried to replace the rootbone of the clothes with that of the character in order to make them move with the main bone but I don’t understand why he keeps holding the one of the clothes and ignoring what I entered. :sunglasses: