# Replace child meshes of an imported mesh using Babylon.js

**URL:** <https://forum.babylonjs.com/t/replace-child-meshes-of-an-imported-mesh-using-babylon-js/20737>\
**Category:** Questions\
**Created:** [May 11, 2021, 8:47am UTC](https://forum.babylonjs.com/t/replace-child-meshes-of-an-imported-mesh-using-babylon-js/20737 "2021-05-11T08:47:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krishna](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/krishna/32/16007_2.png) [@Krishna](https://forum.babylonjs.com/u/Krishna)\
**Post date:** [May 11, 2021, 8:47am UTC](https://forum.babylonjs.com/t/replace-child-meshes-of-an-imported-mesh-using-babylon-js/20737/1 "2021-05-11T08:47:03Z")

</div>

Hi everyone  
I have imported a mesh in pg I can able to change the texture of the childmeshes ( like changing colour) but I want to change the childmesh itself for example if avatar is wearing a t-shirt I wanna replace it with shirt.can I do that using Babylon.js  
@Wingnut help me with this  
Thank you all in advance

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 11, 2021, 11:19am UTC](https://forum.babylonjs.com/t/replace-child-meshes-of-an-imported-mesh-using-babylon-js/20737/2 "2021-05-11T11:19:47Z")

</div>

Welcome aboard!

Yes, you can remove a mesh (`mesh.dispose()` if you want to remove the mesh from the scene or `mesh.setEnabled(false)` if you simply want to hide it) and add a new one.

I think the mesh section of the doc should help you: [Meshes | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/mesh)

Maybe you can provide a playground so that we can help with some code.

---

<div class="post-metadata">

**Author:** ![Krishna](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/krishna/32/16007_2.png) [@Krishna](https://forum.babylonjs.com/u/Krishna)\
**Post date:** [May 11, 2021, 1:19pm UTC](https://forum.babylonjs.com/t/replace-child-meshes-of-an-imported-mesh-using-babylon-js/20737/3 "2021-05-11T13:19:31Z")

</div>

@Evgeni_Popov  
[https://playground.babylonjs.com/#G781N3#2](https://playground.babylonjs.com/#G781N3#2)  
Check this pg  
I want to replace shirt with box mesh

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 11, 2021, 2:45pm UTC](https://forum.babylonjs.com/t/replace-child-meshes-of-an-imported-mesh-using-babylon-js/20737/4 "2021-05-11T14:45:43Z")

</div>

You did not say it was animated…

It will be quite more difficult because you would need that the cube have the same bones than the existing torso for the animation to work as expected.

You can try to use `attachToBone` so that the box follows the same animation than the torso, but it has some limits (also, you need to tweak the box position and scaling to match the model):

[https://playground.babylonjs.com/#G781N3#3](https://playground.babylonjs.com/#G781N3#3)

---

<div class="post-metadata">

**Author:** ![Krishna](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/krishna/32/16007_2.png) [@Krishna](https://forum.babylonjs.com/u/Krishna)\
**Post date:** [May 13, 2021, 7:58am UTC](https://forum.babylonjs.com/t/replace-child-meshes-of-an-imported-mesh-using-babylon-js/20737/5 "2021-05-13T07:58:44Z")

</div>

@Evgeni_Popov I have a mesh with same bones as shirt then how to replace the shirt with that mesh.can you share code snippet

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 13, 2021, 11:13am UTC](https://forum.babylonjs.com/t/replace-child-meshes-of-an-imported-mesh-using-babylon-js/20737/6 "2021-05-13T11:13:21Z")

</div>

Simply hide/remove the old mesh and parent the new mesh to the same parent than the old mesh. You should also assign the same skeleton:

```javascript
newMesh.parent = oldMesh.parent;
newMesh.skeleton = oldMesh.skeleton;
oldMesh.setEnabled(false);
newMesh.setEnabled(true);

```

---

<div class="post-metadata">

**Author:** ![Krishna](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/krishna/32/16007_2.png) [@Krishna](https://forum.babylonjs.com/u/Krishna)\
**Post date:** [May 15, 2021, 12:15pm UTC](https://forum.babylonjs.com/t/replace-child-meshes-of-an-imported-mesh-using-babylon-js/20737/7 "2021-05-15T12:15:27Z")

</div>

@Evgeni_Popov Mesh attached to avatar but animations are not working properly.newmesh has same bones and animations as the oldmesh.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 16, 2021, 10:07am UTC](https://forum.babylonjs.com/t/replace-child-meshes-of-an-imported-mesh-using-babylon-js/20737/8 "2021-05-16T10:07:55Z")

</div>

I guess we will need a PG to be able to help more.
