- Home /
Attach object to bone ingame.
How can I attach an object to a bone during game through code?
Thanks
Answer by Statement · Mar 12, 2011 at 11:02 PM
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.
I know this is now very old, but it seems to work somewhat...except my armour seems to be rotating incorrectly. Is there an update for something like this? I am using U$$anonymous$$A. I am not sure if this has anything to do with it.
Your answer
Follow this Question
Related Questions
Attach object to avatar bone 1 Answer
attaching armor to bone in proper position !!! help! 2 Answers
Attaching an object to a bone? 3 Answers
Parent my Weapon to the HandBone. 1 Answer
Attaching objects on collision 1 Answer