# CSG Issue with merged materials

**URL:** <https://forum.babylonjs.com/t/csg-issue-with-merged-materials/35815>\
**Category:** Questions\
**Created:** [November 18, 2022, 1:58pm UTC](https://forum.babylonjs.com/t/csg-issue-with-merged-materials/35815 "2022-11-18T13:58:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvaisman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bvaisman/32/20835_2.png) [@bvaisman](https://forum.babylonjs.com/u/bvaisman)\
**Post date:** [November 18, 2022, 1:58pm UTC](https://forum.babylonjs.com/t/csg-issue-with-merged-materials/35815/1 "2022-11-18T13:58:31Z")

</div>

Hi everybody,

I have an issue when i try to subtract a CSG mesh with another which is already merged and has several colors.

Case 1 : my merged mesh is not cut :

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/c/bc37551769d61b3280818ef7165b38a5c7ffb993.png)

Case 2 : my merged mesh is cut by another one

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/7/8/789bef4a22656e5c5002c46bcd5551fbde61aff3.png)

Here’s my PG : [https://playground.babylonjs.com/#FL50RB#3](https://playground.babylonjs.com/#FL50RB#3)

I don’t know if its a bug in my code or in Babylon.

Could you help me ?

Thanks in advance,

Boris

---

<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:** [November 18, 2022, 2:20pm UTC](https://forum.babylonjs.com/t/csg-issue-with-merged-materials/35815/2 "2022-11-18T14:20:41Z")

</div>

Wide guess time. Anytime you have 2 operations in series, which work separately but not together, switching the order should be the first thing to try. This should be written down somewhere 😀.

Do the cut(s) first, then merge, & report back, please.

---

<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:** [November 18, 2022, 2:30pm UTC](https://forum.babylonjs.com/t/csg-issue-with-merged-materials/35815/3 "2022-11-18T14:30:35Z")

</div>

You can use the “keepSubMeshes” of the `toMesh` function call:

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

PS: I like your avatar almost as much as mine 🙂

---

<div class="post-metadata">

**Author:** ![bvaisman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bvaisman/32/20835_2.png) [@bvaisman](https://forum.babylonjs.com/u/bvaisman)\
**Post date:** [November 18, 2022, 3:11pm UTC](https://forum.babylonjs.com/t/csg-issue-with-merged-materials/35815/4 "2022-11-18T15:11:16Z")

</div>

Thanks for all @Evgeni_Popov, your solution is easier to use than swiching the order of the tasks. Thanks anyway, @JCPalmer

Captain caveman’s team forever !!! 😁
