How to set Inspector visible properties of node material in code?

Does anyone know how to set a property value of a json exported node material in code?
I fetch in the material from file like this:

    let checkerMat = await NodeMaterial.ParseFromFileAsync('checker_M', './materials/checker.json', this._scene);

then add an observable callback:

    checkerMat.onEffectCreatedObservable.add(data => {
        data.effect.setVector2('repeatXY', new Vector2(100, 50));

when it gets to the setVector2 it says could not find property repeatXY
i tried u_repeatXY as well (as it described as uniform in the fragment shader) but that didnt help.

I created a playground scene to demonstrate the problem:

After page load, open up the browser javascript console output, you can see the error message:
Uncaught TypeError: Cannot read properties of undefined (reading ‘repeatXY’)

You can see in the console output, that the effect instance exists, and if you check in that you can see that the fragment shader has a uniform vec2 named u_repeatXY.
What am I missing here? How to set these kind of parameters in json parsed NodeMaterials?

You need to use nodeMaterial.getBlockByName (or any other getBlockXXX method) to get a pointer on the block and change the value property:

1 Like

This is exactly what I was looking for, thank you! Marked as solved!

If I use typescript, value property is not visible on the NodeMaterialBlock class. I have a workaround to set is as nodeBlock[‘value’] = new Vector2(…).
Is there a more strongly typed approach for typescript?

You can use the nodeMaterial.getInputBlockByPredicate method instead of getBlockByName: