# Attach mesh to bone strange behaviour

**URL:** <https://forum.babylonjs.com/t/attach-mesh-to-bone-strange-behaviour/10169>\
**Category:** Questions\
**Created:** [April 20, 2020, 2:25pm UTC](https://forum.babylonjs.com/t/attach-mesh-to-bone-strange-behaviour/10169 "2020-04-20T14:25:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gugis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gugis/32/7958_2.png) [@Gugis](https://forum.babylonjs.com/u/Gugis)\
**Post date:** [April 20, 2020, 2:25pm UTC](https://forum.babylonjs.com/t/attach-mesh-to-bone-strange-behaviour/10169/1 "2020-04-20T14:25:10Z")

</div>

When I try to attach mesh to a bone during runtime attached mesh ends up having wrong position and rotation. Everything is fine when mesh is attached at code initialization.

 ![Screenshot_1](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/2/295d458fc3b17871b8700645d22f3bd8157b418e.png)  
Here you can see hair mesh is attached to head bones of both characters. On the left during code initialization and on the right after delay (using setTimeout)  
I dont know if it’s something wrong with hair mesh or skeleton of character.  
Here’s playground: [Babylon.js Playground](https://playground.babylonjs.com/#QLFUZR)  
Thank you 🙂

---

<div class="post-metadata">

**Author:** ![JCPalmer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jcpalmer/32/42_2.png) [@JCPalmer](https://forum.babylonjs.com/u/JCPalmer)\
**Post date:** [April 20, 2020, 2:38pm UTC](https://forum.babylonjs.com/t/attach-mesh-to-bone-strange-behaviour/10169/2 "2020-04-20T14:38:28Z")

</div>

If you look starting at line 1679, you will see the definition of the hair mesh. It has no matrix weights nor matrix indices. Attaching it in runtime will add those. You need to get the armature modifier on the hair mesh in Blender to export already attached.

---

<div class="post-metadata">

**Author:** ![Gugis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gugis/32/7958_2.png) [@Gugis](https://forum.babylonjs.com/u/Gugis)\
**Post date:** [April 20, 2020, 2:46pm UTC](https://forum.babylonjs.com/t/attach-mesh-to-bone-strange-behaviour/10169/3 "2020-04-20T14:46:09Z")

</div>

What if I want to attach that mesh to different characters with different armatures? Is it going to work with multiple armature modifiers for same mesh?

---

<div class="post-metadata">

**Author:** ![JCPalmer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jcpalmer/32/42_2.png) [@JCPalmer](https://forum.babylonjs.com/u/JCPalmer)\
**Post date:** [April 20, 2020, 2:57pm UTC](https://forum.babylonjs.com/t/attach-mesh-to-bone-strange-behaviour/10169/4 "2020-04-20T14:57:14Z")

</div>

If you wish attach to different mesh, why not just always attach at run time?

---

<div class="post-metadata">

**Author:** ![Gugis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gugis/32/7958_2.png) [@Gugis](https://forum.babylonjs.com/u/Gugis)\
**Post date:** [April 20, 2020, 2:59pm UTC](https://forum.babylonjs.com/t/attach-mesh-to-bone-strange-behaviour/10169/5 "2020-04-20T14:59:56Z")

</div>

Ok, I applied armature modifier to hair mesh, but results are the same. [https://playground.babylonjs.com/#QLFUZR#1](https://playground.babylonjs.com/#QLFUZR#1)  
I guess I’m misunderstanding something?

> [@JCPalmer](#):
>
> If you wish attach to different mesh, why not just always attach at run time?

My goal is to attach at runtime, but as you see hair is transformed not the way I want.

**EDIT:**

> **[Babylon.js Playground](https://playground.babylonjs.com/#QLFUZR%232)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Here you can see I attach box, and in both cases box is positioned same way.

**MORE EDIT**  
Okay it looks like I have figured it out. Meshes are attached to the head of the bone and in this case head must be pointing upwards. Bone I was attaching to was another way around: head - down, tail - up. And that resulted in hair mesh being rotated 180 degrees along x axis. I have created another bone dedicated for attaching hair and now it looks good.

Sorry for pointless topic 😕
