[SOLVED] Looks like material.clone() has some issue


I found that method material.clone() does not copy material at all.
It doesn’t copy custom shader assigned to the source material, and does not copy list of parameters of source material (parameters of custom shader).

code form engine (playcanvas ver. 164.1):

    Material.prototype._cloneInternal = function(clone) {
    clone.name = this.name;
    clone.id = id++;
    clone.shader = null; // does not copy shader
    clone.parameters = {}; // does not copy parameters
    }, Material.prototype.clone = function() {
    var clone = new pc.Material;
    return clone

Now, every time i need to make copy of material with custom shader, i need copy all parameters and shader manualy from source materail. It’s not convenient.

Is it OK, or it’s a bug?

Hi @Anton. Yes it seems like a bug.
What if you call material.update() straight after clone, does it makes a situation better?

If it is purely engine bug, then the best place to contribute and report it so we fix it quicker is github: https://github.com/playcanvas/engine
If you have a fix, even better then, you can make Pull Request and after we test it we can accept it, so you actually contribute to our engine :smile:

Ok, i did a Pull Request: https://github.com/playcanvas/engine/pull/240
There are a little fixes for clone method for base Material class and for PhongMaterial class.

Well, that was long time ago, but merged now. We shall not forget PR’s in finished states…