So I created Player character in Blender, add him rig, make it animate. Then i made bracelet in the same blender file, attach it model to the character’s skeleton and export like FBX-file. In Unity bracelet prefab parented to the character model. For now bracelet follows player’s position when he moves, but not animate with him. So when player moves, his parts animating, but bracelet don’t go with forearm. In blender when i move forearm, it’s follows properly, so fbx was made fine.
I googled this problem and find kinda solution for this. Here’s script i found:
void Start()
{
int i = 0;
Transform rootParent = transform.root.transform;
GameObject target;
Transform[] bodyBones = null;
var skinnedMesh = transform.parent.GetComponentInChildren<SkinnedMeshRenderer>();
if (skinnedMesh != null)
{
bodyBones = skinnedMesh.bones;
}
if (bodyBones == null)
{
Debug.LogError("Wrong parent body.");
return;
}
GameObject Attachment;
for (i = 0; i < transform.childCount; i++)
{
Attachment = transform.GetChild(i).gameObject;
if (Attachment.GetComponent<SkinnedMeshRenderer>() != null)
{
Attachment.GetComponent<SkinnedMeshRenderer>().bones = bodyBones;
}
}
}
}
As i understand, this supposed to replace one of the bones of character’s skeleton with one, that uses my bracelet prefab. But it didn’t work for me as well. No errors, no massages from the script about not finding target bones. Both character mesh (named “Body”) and the brcelet model has Skinned mesh attached to it. The script is on bracelet. When script attached to anithing else, bracelet mesh just dissapears or goes inside character’s mesh and becomes very small (literally like 0.1 scale) and places in wrong angle.
I can’t find out where i’m do it wrong. Maybe, it’s about poor hierarchy or smth. Please, help, i struggling with this almost whole week.
Sorry for bad English