# Cloning a NodeMaterial

**URL:** <https://forum.babylonjs.com/t/cloning-a-nodematerial/9141>\
**Category:** Questions\
**Tags:** material\
**Created:** [March 11, 2020, 8:48pm UTC](https://forum.babylonjs.com/t/cloning-a-nodematerial/9141 "2020-03-11T20:48:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tyzor/32/1432_2.png) [@Tyzor](https://forum.babylonjs.com/u/Tyzor)\
**Post date:** [March 11, 2020, 8:48pm UTC](https://forum.babylonjs.com/t/cloning-a-nodematerial/9141/1 "2020-03-11T20:48:18Z")

</div>

Is there a reason that the clone operation does not work on NodeMaterials? I have been messing around with NodeMaterial Editor trying to make a forcefield shader. My original plan was to clone the material and provide different Color3 values for different shield colors.

Here is a playground illustrating the issue.  
[https://playground.babylonjs.com/#098LAF#1](https://playground.babylonjs.com/#098LAF#1)

I suppose I could export the shaders and load them in through ShaderMaterial but I’m not very experienced working with GLSL code yet.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 11, 2020, 9:15pm UTC](https://forum.babylonjs.com/t/cloning-a-nodematerial/9141/2 "2020-03-11T21:15:03Z")

</div>

This looks like it might work as a workaround: [https://playground.babylonjs.com/#098LAF#2](https://playground.babylonjs.com/#098LAF#2)

I ll check if I can add a clone function to the nodeMaterial.

---

<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:** [March 11, 2020, 9:16pm UTC](https://forum.babylonjs.com/t/cloning-a-nodematerial/9141/3 "2020-03-11T21:16:07Z")

</div>

As I can see it, the `clone` method is not implemented in the `NodeMaterial` class, so you get the default implementation that simply returns `null`.

I don’t know if implementing the function is planned but in the meantime you can simply reload the material:

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

[EDIT] Ah, @sebavan solution is better than mine! [/EDIT]

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 11, 2020, 9:17pm UTC](https://forum.babylonjs.com/t/cloning-a-nodematerial/9141/4 "2020-03-11T21:17:14Z")

</div>

Our messages crossed 🙂 so 2 workarounds and I ll look into adding the clone 🙂

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 11, 2020, 9:53pm UTC](https://forum.babylonjs.com/t/cloning-a-nodematerial/9141/5 "2020-03-11T21:53:23Z")

</div>

Should be up in 10 minutes

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 11, 2020, 9:59pm UTC](https://forum.babylonjs.com/t/cloning-a-nodematerial/9141/6 "2020-03-11T21:59:37Z")

</div>

All in your playground now works 🙂  
[https://playground.babylonjs.com/#098LAF#5](https://playground.babylonjs.com/#098LAF#5)

---

<div class="post-metadata">

**Author:** ![Tyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tyzor/32/1432_2.png) [@Tyzor](https://forum.babylonjs.com/u/Tyzor)\
**Post date:** [March 12, 2020, 7:52pm UTC](https://forum.babylonjs.com/t/cloning-a-nodematerial/9141/7 "2020-03-12T19:52:57Z")

</div>

Ah thanks the update works great! Now my follow-up question would be how do I get this latest build from the ES6 npm packages? Do I need to pull the preview tag?

I can always use the workarounds for npm builds in the meantime.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 12, 2020, 7:56pm UTC](https://forum.babylonjs.com/t/cloning-a-nodematerial/9141/8 "2020-03-12T19:56:44Z")

</div>

Yup, I just published 15 min ago so just install preview and you should be good to go.
