Attach object to bone ingame.

How can I attach an object to a bone during game through code?

Thanks

To attach an object to another, set the transform.parent to the object you want to parent to.

I assume you have some GameObject you want to add to some bone transform.

someGameObject.transform.parent = someBone;

If you want to place it right on the bone as well you can try:

var someTransform = someGameObject.transform;
someTransform.parent = someBone;
someTransform.localPosition = Vector3.zero;
someTransform.localRotation = Quaternion.identity;
someTransform.localScale = Vector3.one;

If you want to find a particular bone in a character use transform.Find:

var someBone = transform.Find("LeftShoulder/Arm/Hand/Finger");

The code should work in either C# or JS.