Any example of updating Shadergraph shader's parameter through script?

something like this? getComponentInChildren(Renderer)?.sharedMaterial.setValues("_FadeAmount",1);

Original Post on Discord

by user 263967078346653697

you just set the property in threejs, we expose all of them directly.
Your example: myMaterials._FadeAmount = 1

so id have to have a reference of just that material?

by user 263967078346653697

You can use the sharedMaterials array as well

if you know that all those materials have that property/shader

this.gameObject.getComponentInChildren(Renderer).sharedMaterial._FadeAmount = 1

how can i get ā€œ_FadeAmountā€ to not throw error?

by user 263967078346653697

be recognized as the variable of that materialā€™s shader

by user 263967078346653697

What error do you get

Property ā€˜_FadeAmountā€™ does not exist on type ā€˜Rendererā€™

by user 263967078346653697

the script doesnt event know which material im using yet

by user 263967078346653697

so itā€™s natural id get it

by user 263967078346653697

It doesnt exist on the renderer but on the material

woops my bad

by user 263967078346653697

Property ā€˜_FadeAmountā€™ does not exist on type ā€˜Materialā€™

by user 263967078346653697

im trying like so

by user 263967078346653697

image.png

by user 263967078346653697

just as a test

by user 263967078346653697

im sorry im clueless on this

by user 263967078346653697

Thatā€™s typescript complaining since the base material type you get doesnt have / know your custom properties. So you have 3 options:

  1. chaotic: add @ts-ignore above that line
  2. neutral: access like sharedMaterial["_FadeAmount"]
  3. good: delcare a custom merged type with your properties
declare type MyMaterial = {
    _FadeAmount : number;
} & Material;