Scripting for Material Instance Animations

Hi @bdb and welcome,

Nice example! Yes, material instances as you define them are supported in PlayCanvas by accessing and setting the material properties directly on a mesh instance.

You will have to use the setParameter method, which works the same both on the material and on the mesh instance level. Although the parameters are undocumented for the moment and are subject to change.

For example to set the diffuse channel transform (offset/tiling) you can do this directly on a mesh instance, and it will affect only that mesh instance:

   this.uniform0[0] = tileWidth;
    this.uniform0[1] = 0;
    this.uniform0[2] = tileOffsetX;
    
    this.uniform1[0] = 0; 
    this.uniform1[1] = tileHeight;
    this.uniform1[2] = tileOffsetY;
    
    meshInstance.setParameter("texture_diffuseMapTransform0", this.uniform0);

Source: Material parameter uniform names have changed since 1.46.0

2 Likes