- Home /
How do you access or change a material's color information in script when using the Lightweight Rendering Pipeline?
It seems that the API related to Material.color doesn't work with the LWRP. For example, the sample code here (https://docs.unity3d.com/ScriptReference/Material-color.html) appears to do nothing when applied to a cube in the LWRP template project's sample scene.
Answer by Paul_Hughes · Sep 02, 2019 at 11:54 AM
Hi, I am having difficulty when swapping to LWRP also, my fix just now is this.
Create any new material with the corresponding colors you wish to use and access then from the code, i.e.
public Material yellowmat; public Material bluemat;
Then during Update()
access the materials using GetComponent().material = yellowmat or bluemat; for instance I use if a target is visible then swap the materials
if(targetIsVisable){ GetComponent().material = yellowmat; } else GetComponent.material = bluemat;
I hope this helps as a quick fix until it can be done quicker?
I would also like a lot more information on this topic and a whole book on learning the pipelines etc as I am quite new to all this.