Controlling Material parameters from js

I want to change the tiling, and I did this:

var box=app.scene.root.findByName("Box").model.meshInstances[0];
box.material.diffuseMapOffset=new pc.Vec2(.5,.5);

But, nothing happened. How do I change those settings from js?

This works:


But is this the right way?

Edit: Nope. Not working anymore

That should throw an error.

findByName returns a graphNode and material is not a property of a graphNode.

It is returning an entity for me and I can manipulate the instance Ok. :no_mouth:

And I am also able to get the material.

Entity inherits from graphNode. In any case, material is not a property of either.


//from console"2D Box1b").model.meshInstances[0].material

StandardMaterial {name: "Material", id: 28, _shader: Shader, variants: {…}, parameters: {…}, …}

Oops, my bad. Mobile view chopped off the model.meshInstances[0] part.

I only saw:

var box=app.scene.root.findByName("Box");
box.material.diffuseMapOffset=new pc.Vec2(.5,.5);


It seems if I set the tiling from the editor, I can update. Otherwise, the parameters are missing from the shader.

Seems to work fine here?

I think I’ll try to make a new project to see if I can isolate it. I feel like I tried everything :dizzy_face:

My material has extra settings on opacity. Could be the reason??

Test Project

Yeah, opacityMapOffset needs to be set as well as I’m having an alpha channel :sweat_smile:
6 hours of struggle took me away from my main experiment :sob: