Material Update not working

I have been wanting to make a material with texture movement, I had already done it in another project and it worked well for me, but in this project it does not work for me.
this is my code for the animation of the material.


The method update works fine, the texture changes the value of its offset in Diffuse and Emissive, but the problem is that the material update does not make it visual.


I hope you can help me, thank you.
This is my scene:
https://playcanvas.com/editor/scene/1265769

Hmm, for some reason, this.entity.render.material is returning the default material which doesn’t look right.

For the moment, the following will work:

var MagmaMovement = pc.createScript('magmaMovement');
// initialize code called once per entity
MagmaMovement.prototype.initialize = function() {
    this.tmp = new pc.Vec2();
    this.speed=new pc.Vec2(0.5,0);
    
    this.material_magma = this.entity.render.meshInstances[0].material;
};
// update code called every frame
MagmaMovement.prototype.update = function(dt) {
    var tmp = this.tmp;
    tmp.set(this.speed.x, this.speed.y);
    tmp.scale(dt);
    if(this.material_magma){
        this.material_magma.diffuseMapOffset = this.material_magma.diffuseMapOffset.add(tmp);
        this.material_magma.emissiveMapOffset = this.material_magma.emissiveMapOffset.add(tmp);
        //this.material_magma.normalMapOffset.add(tmp);
        this.material_magma.update();
    }
};

eg https://playcanvas.com/editor/scene/1265876

1 Like

Thank you so much yaustar its working! :smiley:

Reported bug: https://github.com/playcanvas/engine/issues/3664

2 Likes