# Parenting object to bone (getting correct position)

**URL:** <https://discourse.threejs.org/t/parenting-object-to-bone-getting-correct-position/4336>\
**Category:** Questions\
**Tags:** animation\
**Created:** [October 2, 2018, 11:20pm UTC](https://discourse.threejs.org/t/parenting-object-to-bone-getting-correct-position/4336 "2018-10-02T23:20:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Tipton](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@Michael\_Tipton](https://discourse.threejs.org/u/Michael_Tipton)\
**Post date:** [October 2, 2018, 11:20pm UTC](https://discourse.threejs.org/t/parenting-object-to-bone-getting-correct-position/4336/1 "2018-10-02T23:20:23Z")

</div>

I’m trying to correctly position an object when parenting it to a bone but when I add it to a bone, it gets translated.  
It imports in the right position when I just import it but don’t add to a bone. Do I need to do something to zero the object before I add it to the bone?

---

<div class="post-metadata">

**Author:** ![calrk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/calrk/32/2746_2.png) [@calrk](https://discourse.threejs.org/u/calrk)\
**Post date:** [October 2, 2018, 11:34pm UTC](https://discourse.threejs.org/t/parenting-object-to-bone-getting-correct-position/4336/2 "2018-10-02T23:34:01Z")

</div>

There is the SceneUtils helper to do this:

> <https://github.com/mrdoob/three.js/blob/dev/examples/js/utils/SceneUtils.js>

The code is small enough that you can just replicate it in your project or you can include it from the examples.

instead of `bone.add(object)` you would use: `SceneUtils.attach(object, object.parent, bone);`  
This will apply the inverse transform of `bone` to `object`, remove the object from its parent and add it to your bone keeping its original 3d position.

If the object does not have a parent yet, use: `SceneUtils.attach(object, scene, bone);`

---

<div class="post-metadata">

**Author:** ![Michael\_Tipton](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@Michael\_Tipton](https://discourse.threejs.org/u/Michael_Tipton)\
**Post date:** [October 2, 2018, 11:44pm UTC](https://discourse.threejs.org/t/parenting-object-to-bone-getting-correct-position/4336/3 "2018-10-02T23:44:59Z")

</div>

Awesome! Extremely helpful. Thanks so much 😃

---

<div class="post-metadata">

**Author:** ![Michael\_Tipton](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@Michael\_Tipton](https://discourse.threejs.org/u/Michael_Tipton)\
**Post date:** [October 3, 2018, 2:15am UTC](https://discourse.threejs.org/t/parenting-object-to-bone-getting-correct-position/4336/4 "2018-10-03T02:15:29Z")

</div>

So this works really well if my model starts in the rest pose. If I’ve moved the model at all, the object im importing will come into the scene where it would should go if the model was still in the rest pose. How do I apply whatever delta there is between the rest pose and current pose?

---

<div class="post-metadata">

**Author:** ![calrk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/calrk/32/2746_2.png) [@calrk](https://discourse.threejs.org/u/calrk)\
**Post date:** [October 3, 2018, 3:55am UTC](https://discourse.threejs.org/t/parenting-object-to-bone-getting-correct-position/4336/5 "2018-10-03T03:55:31Z")

</div>

Not sure if this will solve the problem, I’m not too familiar with how bones work specifically.

In the attach function, you may need to call:  
`parent.updateMatrixWorld();`  
in order to update the matrix of the bone to take into account for its new transformations

---

<div class="post-metadata">

**Author:** ![Michael\_Tipton](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@Michael\_Tipton](https://discourse.threejs.org/u/Michael_Tipton)\
**Post date:** [October 3, 2018, 1:36pm UTC](https://discourse.threejs.org/t/parenting-object-to-bone-getting-correct-position/4336/6 "2018-10-03T13:36:42Z")

</div>

This didn’t immediately fix the problem, but I suspect this is because I’m just not implementing it correctly or not implementing all steps. Can I call updateMatrixWorld on a bone? or should I call it on the model which has the attached armature and then it will recursively be applied to all children?

---

<div class="post-metadata">

**Author:** ![calrk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/calrk/32/2746_2.png) [@calrk](https://discourse.threejs.org/u/calrk)\
**Post date:** [October 3, 2018, 11:33pm UTC](https://discourse.threejs.org/t/parenting-object-to-bone-getting-correct-position/4336/7 "2018-10-03T23:33:24Z")

</div>

Hard to debug without a working example, but the code should look like the following:

```auto
rootBone.updateMatrixWorld(true);
SceneUtils.attach(object, scene, bone);

```

You can try out `bone.updateMatrixWorld();` but I’m not sure that it will update with it’s parent transforms properly.
